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.2.1 to 3.3.0

src/baseTransaction.ts

81

CHANGELOG.md

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

## 3.3.0 - 2021-07-08
### Finalized London HF Support
This release integrates a `Common` library version which provides the `london` HF blocks for all networks including `mainnet` and is therefore the first release with finalized London HF support.
### Improved L2 Tx Support
This tx release bumps the `Common` library dependency version to `v2.4.0` and is therefore assured to work with the reworked `Common.custom()` method which can be used for an easier instantiation of common custom chain instances for sending txs to a custom (L2) network.
`Common.custom()` comes with support for predefined custom chains (Arbitrum testnet, Polygon testnet & mainnet, xDai chain), see e.g. the following code example:
```typescript
import { Transaction } from '@ethereumjs/tx'
import Common from '@ethereumjs/common'
const from = 'PUBLIC_KEY'
const PRIV_KEY = process.argv[2]
const to = 'DESTINATION_ETHEREUM_ADDRESS'
const common = Common.custom(CustomChain.xDaiChain)
const txData = {
from,
nonce: 0,
gasPrice: 1000000000,
gasLimit: 21000,
to,
value: 1,
}
const tx = Transaction.fromTxData(txData, { common })
const signedTx = tx.sign(Buffer.from(PRIV_KEY, 'hex'))
```
For a non-predefined custom chain it is also possible to just provide a chain ID as well as other parameters to `Common`:
```typescript
const common = Common.custom({ chainId: 1234 })
```
See the tx [README](https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/tx) for some more detailed documentation on the new improved L2 support for the tx library.
### New supports(capability) Method
There is a new `tx.supports(capability)` method which can be used for a cleaner and more future-proof switch on txs based on the supported (EIP) capabilities. This is useful if you don't know about your tx type in advance, e.g. since txs are taken from a generic source (a tx pool, user input,...) and instantiated with the provided tx factory.
While it sometimes might make sense to do a switch by `tx.type` it is often more fitting a use case (and also more future proof) to do a switch by a desired tx capability. Does the tx support an EIP-1559 style gas fee market mechanism? Does the tx support access lists?
Such a switch can now be done with the method above
```typescript
import { Transaction, Capability } from '@ethereumjs/tx'
// 1. Instantiate tx
// 2. Switch by capability
if (tx.supports(Capability.EIP2930AccessLists)) {
// Do something which only makes sense for txs with support for access lists
}
```
The following capabilities are currently supported:
```typescript
enum Capabilitiy {
EIP155ReplayProtection: 155, // Only for legacy txs
EIP1559FeeMarket: 1559,
EIP2718TypedTransaction: 2718, // Use for a typed-tx-or-not switch
EIP2930AccessLists: 2930
}
```
### Included Source Files
Source files from the `src` folder are now included in the distribution build, see PR [#1301](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1301). This allows for a better debugging experience in debug tools like Chrome DevTools by having working source map references to the original sources available for inspection.
## 3.2.1 - 2021-06-11

@@ -81,5 +158,5 @@

### London HF Support
### Functional London HF Support (no finalized HF blocks yet)
This `Tx` release comes with full support for the `london` hardfork. There is a new [EIP-1559](https://eips.ethereum.org/EIPS/eip-1559) transaction type `FeeMarketEIP1559Transaction` (type `2`) added together with the new data types `FeeMarketEIP1559TxData` (for instantiation with the `fromTxData()` static constructor method) and `FeeMarketEIP1559ValuesArray` (for instantiation with `fromValuesArray()`), see PR [#1148](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1148) for the main implementation work.
This `Tx` release comes with full functional support for the `london` hardfork (all EIPs are finalized and integrated and `london` HF can be activated, there are no final block numbers for the HF integrated though yet). There is a new [EIP-1559](https://eips.ethereum.org/EIPS/eip-1559) transaction type `FeeMarketEIP1559Transaction` (type `2`) added together with the new data types `FeeMarketEIP1559TxData` (for instantiation with the `fromTxData()` static constructor method) and `FeeMarketEIP1559ValuesArray` (for instantiation with `fromValuesArray()`), see PR [#1148](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1148) for the main implementation work.

@@ -86,0 +163,0 @@ An `EIP-1559` tx inherits the access list feature from the `AccessListEIP2930Transaction` (type `1`) but comes with its own gas fee market mechanism. There is no `gasPrice` field in favor of two new gas related properties `maxFeePerGas` - which represents the total gas fee the tx sender is willing to pay for the tx (including the priority fee) - and the `maxPriorityFeePerGas` property - which represents the fee the sender is willing to give as some tip to the miner to prioritize a tx.

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

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

@@ -26,2 +26,8 @@ * This base class will likely be subject to further

/**
* List of tx type defining EIPs,
* e.g. 1559 (fee market) and 2930 (access lists)
* for FeeMarketEIP1559Transaction objects
*/
protected activeCapabilities: number[];
/**
* The default chain the tx falls back to if no Common

@@ -44,3 +50,3 @@ * is provided and if the chain can't be derived from

/**
* Alias for `type`
* Alias for {@link BaseTransaction.type}
*

@@ -57,2 +63,19 @@ * @deprecated Use `type` instead

/**
* Checks if a tx type defining capability is active
* on a tx, for example the EIP-1559 fee market mechanism
* or the EIP-2930 access list feature.
*
* Note that this is different from the tx type itself,
* so EIP-2930 access lists can very well be active
* on an EIP-1559 tx for example.
*
* This method can be useful for feature checks if the
* tx type is unknown (e.g. when instantiated with
* the tx factory).
*
* See `Capabilites` in the `types` module for a reference
* on all supported capabilities.
*/
supports(capability: Capability): boolean;
/**
* Checks if the transaction has the minimum amount of gas required

@@ -125,3 +148,3 @@ * (DataFee + TxFee + Creation Fee).

*
* @param common - Common instance from tx options
* @param common - {@link Common} instance from tx options
* @param chainId - Chain ID from tx options (typed txs) or signature (legacy tx)

@@ -128,0 +151,0 @@ */

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

var ethereumjs_util_1 = require("ethereumjs-util");
var types_1 = require("./types");
/**

@@ -47,2 +48,8 @@ * This base class will likely be subject to further

/**
* List of tx type defining EIPs,
* e.g. 1559 (fee market) and 2930 (access lists)
* for FeeMarketEIP1559Transaction objects
*/
this.activeCapabilities = [];
/**
* The default chain the tx falls back to if no Common

@@ -87,3 +94,3 @@ * is provided and if the chain can't be derived from

/**
* Alias for `type`
* Alias for {@link BaseTransaction.type}
*

@@ -110,2 +117,21 @@ * @deprecated Use `type` instead

});
/**
* Checks if a tx type defining capability is active
* on a tx, for example the EIP-1559 fee market mechanism
* or the EIP-2930 access list feature.
*
* Note that this is different from the tx type itself,
* so EIP-2930 access lists can very well be active
* on an EIP-1559 tx for example.
*
* This method can be useful for feature checks if the
* tx type is unknown (e.g. when instantiated with
* the tx factory).
*
* See `Capabilites` in the `types` module for a reference
* on all supported capabilities.
*/
BaseTransaction.prototype.supports = function (capability) {
return this.activeCapabilities.includes(capability);
};
BaseTransaction.prototype.validate = function (stringError) {

@@ -201,5 +227,24 @@ if (stringError === void 0) { stringError = false; }

}
// Hack for the constellation that we have got a legacy tx after spuriousDragon with a non-EIP155 conforming signature
// and want to recreate a signature (where EIP155 should be applied)
// Leaving this hack lets the legacy.spec.ts -> sign(), verifySignature() test fail
// 2021-06-23
var hackApplied = false;
if (this.type === 0 &&
this.common.gteHardfork('spuriousDragon') &&
!this.supports(types_1.Capability.EIP155ReplayProtection)) {
this.activeCapabilities.push(types_1.Capability.EIP155ReplayProtection);
hackApplied = true;
}
var msgHash = this.getMessageToSign(true);
var _a = ethereumjs_util_1.ecsign(msgHash, privateKey), v = _a.v, r = _a.r, s = _a.s;
return this._processSignature(v, r, s);
var tx = this._processSignature(v, r, s);
// Hack part 2
if (hackApplied) {
var index = this.activeCapabilities.indexOf(types_1.Capability.EIP155ReplayProtection);
if (index > -1) {
this.activeCapabilities.splice(index, 1);
}
}
return tx;
};

@@ -211,3 +256,3 @@ /**

*
* @param common - Common instance from tx options
* @param common - {@link Common} instance from tx options
* @param chainId - Chain ID from tx options (typed txs) or signature (legacy tx)

@@ -214,0 +259,0 @@ */

10

dist.browser/eip1559Transaction.d.ts
/// <reference types="bn.js" />
/// <reference types="node" />
import { BN } from 'ethereumjs-util';
import Common from '@ethereumjs/common';
import { BN } from 'ethereumjs-util';
import { BaseTransaction } from './baseTransaction';

@@ -65,3 +65,3 @@ import { AccessList, AccessListBuffer, FeeMarketEIP1559TxData, FeeMarketEIP1559ValuesArray, JsonTx, TxOptions } from './types';

* Instantiate a transaction from the serialized tx.
* (alias of `fromSerializedTx()`)
* (alias of {@link FeeMarketEIP1559Transaction.fromSerializedTx})
*

@@ -71,3 +71,3 @@ * Note: This means that the Buffer should start with 0x01.

* @deprecated this constructor alias is deprecated and will be removed
* in favor of the `fromSerializedTx()` constructor
* in favor of the {@link FeeMarketEIP1559Transaction.fromSerializedTx} constructor
*/

@@ -105,3 +105,3 @@ static fromRlpSerializedTx(serialized: Buffer, opts?: TxOptions): FeeMarketEIP1559Transaction;

*
* Use `serialize()` to add to block data for `Block.fromValuesArray()`.
* Use {@link FeeMarketEIP1559Transaction.serialize} to add to block data for {@link Block.fromValuesArray}.
*/

@@ -139,3 +139,3 @@ raw(): FeeMarketEIP1559ValuesArray;

* This method can only be used for signed txs (it throws otherwise).
* Use `getMessageToSign()` to get a tx hash for the purpose of signing.
* Use {@link FeeMarketEIP1559Transaction.getMessageToSign} to get a tx hash for the purpose of signing.
*/

@@ -142,0 +142,0 @@ hash(): Buffer;

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

}
_this.activeCapabilities = _this.activeCapabilities.concat([1559, 2718, 2930]);
// Populate the access list fields

@@ -180,3 +181,3 @@ var accessListData = util_1.AccessLists.getAccessListData(accessList !== null && accessList !== void 0 ? accessList : []);

* Instantiate a transaction from the serialized tx.
* (alias of `fromSerializedTx()`)
* (alias of {@link FeeMarketEIP1559Transaction.fromSerializedTx})
*

@@ -186,3 +187,3 @@ * Note: This means that the Buffer should start with 0x01.

* @deprecated this constructor alias is deprecated and will be removed
* in favor of the `fromSerializedTx()` constructor
* in favor of the {@link FeeMarketEIP1559Transaction.fromSerializedTx} constructor
*/

@@ -244,18 +245,18 @@ FeeMarketEIP1559Transaction.fromRlpSerializedTx = function (serialized, opts) {

*
* Use `serialize()` to add to block data for `Block.fromValuesArray()`.
* Use {@link FeeMarketEIP1559Transaction.serialize} to add to block data for {@link Block.fromValuesArray}.
*/
FeeMarketEIP1559Transaction.prototype.raw = function () {
return [
ethereumjs_util_1.bnToRlp(this.chainId),
ethereumjs_util_1.bnToRlp(this.nonce),
ethereumjs_util_1.bnToRlp(this.maxPriorityFeePerGas),
ethereumjs_util_1.bnToRlp(this.maxFeePerGas),
ethereumjs_util_1.bnToRlp(this.gasLimit),
ethereumjs_util_1.bnToUnpaddedBuffer(this.chainId),
ethereumjs_util_1.bnToUnpaddedBuffer(this.nonce),
ethereumjs_util_1.bnToUnpaddedBuffer(this.maxPriorityFeePerGas),
ethereumjs_util_1.bnToUnpaddedBuffer(this.maxFeePerGas),
ethereumjs_util_1.bnToUnpaddedBuffer(this.gasLimit),
this.to !== undefined ? this.to.buf : Buffer.from([]),
ethereumjs_util_1.bnToRlp(this.value),
ethereumjs_util_1.bnToUnpaddedBuffer(this.value),
this.data,
this.accessList,
this.v !== undefined ? ethereumjs_util_1.bnToRlp(this.v) : Buffer.from([]),
this.r !== undefined ? ethereumjs_util_1.bnToRlp(this.r) : Buffer.from([]),
this.s !== undefined ? ethereumjs_util_1.bnToRlp(this.s) : Buffer.from([]),
this.v !== undefined ? ethereumjs_util_1.bnToUnpaddedBuffer(this.v) : Buffer.from([]),
this.r !== undefined ? ethereumjs_util_1.bnToUnpaddedBuffer(this.r) : Buffer.from([]),
this.s !== undefined ? ethereumjs_util_1.bnToUnpaddedBuffer(this.s) : Buffer.from([]),
];

@@ -292,3 +293,3 @@ };

* This method can only be used for signed txs (it throws otherwise).
* Use `getMessageToSign()` to get a tx hash for the purpose of signing.
* Use {@link FeeMarketEIP1559Transaction.getMessageToSign} to get a tx hash for the purpose of signing.
*/

@@ -324,3 +325,3 @@ FeeMarketEIP1559Transaction.prototype.hash = function () {

return ethereumjs_util_1.ecrecover(msgHash, v.addn(27), // Recover the 27 which was stripped from ecsign
ethereumjs_util_1.bnToRlp(r), ethereumjs_util_1.bnToRlp(s));
ethereumjs_util_1.bnToUnpaddedBuffer(r), ethereumjs_util_1.bnToUnpaddedBuffer(s));
}

@@ -327,0 +328,0 @@ catch (e) {

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

@@ -64,3 +64,3 @@ import { AccessList, AccessListBuffer, AccessListEIP2930TxData, AccessListEIP2930ValuesArray, JsonTx, TxOptions } from './types';

* Instantiate a transaction from the serialized tx.
* (alias of `fromSerializedTx()`)
* (alias of {@link AccessListEIP2930Transaction.fromSerializedTx})
*

@@ -70,3 +70,3 @@ * Note: This means that the Buffer should start with 0x01.

* @deprecated this constructor alias is deprecated and will be removed
* in favor of the `fromSerializedTx()` constructor
* in favor of the {@link AccessListEIP2930Transaction.fromSerializedTx} constructor
*/

@@ -103,3 +103,3 @@ static fromRlpSerializedTx(serialized: Buffer, opts?: TxOptions): AccessListEIP2930Transaction;

*
* Use `serialize()` to add to block data for `Block.fromValuesArray()`.
* Use {@link AccessListEIP2930Transaction.serialize} to add to block data for {@link Block.fromValuesArray}.
*/

@@ -136,3 +136,3 @@ raw(): AccessListEIP2930ValuesArray;

* This method can only be used for signed txs (it throws otherwise).
* Use `getMessageToSign()` to get a tx hash for the purpose of signing.
* Use {@link AccessListEIP2930Transaction.getMessageToSign} to get a tx hash for the purpose of signing.
*/

@@ -139,0 +139,0 @@ hash(): Buffer;

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

}
_this.activeCapabilities = _this.activeCapabilities.concat([2718, 2930]);
// Populate the access list fields

@@ -174,3 +175,3 @@ var accessListData = util_1.AccessLists.getAccessListData(accessList !== null && accessList !== void 0 ? accessList : []);

* Instantiate a transaction from the serialized tx.
* (alias of `fromSerializedTx()`)
* (alias of {@link AccessListEIP2930Transaction.fromSerializedTx})
*

@@ -180,3 +181,3 @@ * Note: This means that the Buffer should start with 0x01.

* @deprecated this constructor alias is deprecated and will be removed
* in favor of the `fromSerializedTx()` constructor
* in favor of the {@link AccessListEIP2930Transaction.fromSerializedTx} constructor
*/

@@ -234,17 +235,17 @@ AccessListEIP2930Transaction.fromRlpSerializedTx = function (serialized, opts) {

*
* Use `serialize()` to add to block data for `Block.fromValuesArray()`.
* Use {@link AccessListEIP2930Transaction.serialize} to add to block data for {@link Block.fromValuesArray}.
*/
AccessListEIP2930Transaction.prototype.raw = function () {
return [
ethereumjs_util_1.bnToRlp(this.chainId),
ethereumjs_util_1.bnToRlp(this.nonce),
ethereumjs_util_1.bnToRlp(this.gasPrice),
ethereumjs_util_1.bnToRlp(this.gasLimit),
ethereumjs_util_1.bnToUnpaddedBuffer(this.chainId),
ethereumjs_util_1.bnToUnpaddedBuffer(this.nonce),
ethereumjs_util_1.bnToUnpaddedBuffer(this.gasPrice),
ethereumjs_util_1.bnToUnpaddedBuffer(this.gasLimit),
this.to !== undefined ? this.to.buf : Buffer.from([]),
ethereumjs_util_1.bnToRlp(this.value),
ethereumjs_util_1.bnToUnpaddedBuffer(this.value),
this.data,
this.accessList,
this.v !== undefined ? ethereumjs_util_1.bnToRlp(this.v) : Buffer.from([]),
this.r !== undefined ? ethereumjs_util_1.bnToRlp(this.r) : Buffer.from([]),
this.s !== undefined ? ethereumjs_util_1.bnToRlp(this.s) : Buffer.from([]),
this.v !== undefined ? ethereumjs_util_1.bnToUnpaddedBuffer(this.v) : Buffer.from([]),
this.r !== undefined ? ethereumjs_util_1.bnToUnpaddedBuffer(this.r) : Buffer.from([]),
this.s !== undefined ? ethereumjs_util_1.bnToUnpaddedBuffer(this.s) : Buffer.from([]),
];

@@ -294,3 +295,3 @@ };

* This method can only be used for signed txs (it throws otherwise).
* Use `getMessageToSign()` to get a tx hash for the purpose of signing.
* Use {@link AccessListEIP2930Transaction.getMessageToSign} to get a tx hash for the purpose of signing.
*/

@@ -326,3 +327,3 @@ AccessListEIP2930Transaction.prototype.hash = function () {

return ethereumjs_util_1.ecrecover(msgHash, yParity.addn(27), // Recover the 27 which was stripped from ecsign
ethereumjs_util_1.bnToRlp(r), ethereumjs_util_1.bnToRlp(s));
ethereumjs_util_1.bnToUnpaddedBuffer(r), ethereumjs_util_1.bnToUnpaddedBuffer(s));
}

@@ -329,0 +330,0 @@ catch (e) {

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

* Instantiate a transaction from the serialized tx.
* (alias of `fromSerializedTx()`)
* (alias of {@link Transaction.fromSerializedTx})
*
* @deprecated this constructor alias is deprecated and will be removed
* in favor of the `fromSerializedTx()` constructor
* in favor of the {@link Transaction.fromSerializedTx} constructor
*/

@@ -58,3 +58,3 @@ static fromRlpSerializedTx(serialized: Buffer, opts?: TxOptions): Transaction;

* for the signature parameters `v`, `r` and `s`. For an EIP-155 compliant
* representation have a look at the `getMessageToSign()` method.
* representation have a look at {@link Transaction.getMessageToSign}.
*/

@@ -69,6 +69,5 @@ raw(): TxValuesArray;

* for the signature parameters `v`, `r` and `s` for encoding. For an
* EIP-155 compliant representation use the `getMessageToSign()` method.
* EIP-155 compliant representation use {@link Transaction.getMessageToSign}.
*/
serialize(): Buffer;
private _unsignedTxImplementsEIP155;
private _getMessageToSign;

@@ -100,3 +99,3 @@ /**

* This method can only be used for signed txs (it throws otherwise).
* Use `getMessageToSign()` to get a tx hash for the purpose of signing.
* Use {@link Transaction.getMessageToSign} to get a tx hash for the purpose of signing.
*/

@@ -124,3 +123,10 @@ hash(): Buffer;

private _validateTxV;
/**
* @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;
}

@@ -66,2 +66,20 @@ "use strict";

_this._validateCannotExceedMaxInteger({ gasPrice: _this.gasPrice });
if (_this.common.gteHardfork('spuriousDragon')) {
if (!_this.isSigned()) {
_this.activeCapabilities.push(types_1.Capability.EIP155ReplayProtection);
}
else {
// 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.
var v = _this.v;
var 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))) {
_this.activeCapabilities.push(types_1.Capability.EIP155ReplayProtection);
}
}
}
var freeze = (_a = opts === null || opts === void 0 ? void 0 : opts.freeze) !== null && _a !== void 0 ? _a : true;

@@ -100,6 +118,6 @@ if (freeze) {

* Instantiate a transaction from the serialized tx.
* (alias of `fromSerializedTx()`)
* (alias of {@link Transaction.fromSerializedTx})
*
* @deprecated this constructor alias is deprecated and will be removed
* in favor of the `fromSerializedTx()` constructor
* in favor of the {@link Transaction.fromSerializedTx} constructor
*/

@@ -142,15 +160,15 @@ Transaction.fromRlpSerializedTx = function (serialized, opts) {

* for the signature parameters `v`, `r` and `s`. For an EIP-155 compliant
* representation have a look at the `getMessageToSign()` method.
* representation have a look at {@link Transaction.getMessageToSign}.
*/
Transaction.prototype.raw = function () {
return [
ethereumjs_util_1.bnToRlp(this.nonce),
ethereumjs_util_1.bnToRlp(this.gasPrice),
ethereumjs_util_1.bnToRlp(this.gasLimit),
ethereumjs_util_1.bnToUnpaddedBuffer(this.nonce),
ethereumjs_util_1.bnToUnpaddedBuffer(this.gasPrice),
ethereumjs_util_1.bnToUnpaddedBuffer(this.gasLimit),
this.to !== undefined ? this.to.buf : Buffer.from([]),
ethereumjs_util_1.bnToRlp(this.value),
ethereumjs_util_1.bnToUnpaddedBuffer(this.value),
this.data,
this.v !== undefined ? ethereumjs_util_1.bnToRlp(this.v) : Buffer.from([]),
this.r !== undefined ? ethereumjs_util_1.bnToRlp(this.r) : Buffer.from([]),
this.s !== undefined ? ethereumjs_util_1.bnToRlp(this.s) : Buffer.from([]),
this.v !== undefined ? ethereumjs_util_1.bnToUnpaddedBuffer(this.v) : Buffer.from([]),
this.r !== undefined ? ethereumjs_util_1.bnToUnpaddedBuffer(this.r) : Buffer.from([]),
this.s !== undefined ? ethereumjs_util_1.bnToUnpaddedBuffer(this.s) : Buffer.from([]),
];

@@ -165,3 +183,3 @@ };

* for the signature parameters `v`, `r` and `s` for encoding. For an
* EIP-155 compliant representation use the `getMessageToSign()` method.
* EIP-155 compliant representation use {@link Transaction.getMessageToSign}.
*/

@@ -171,15 +189,12 @@ Transaction.prototype.serialize = function () {

};
Transaction.prototype._unsignedTxImplementsEIP155 = function () {
return this.common.gteHardfork('spuriousDragon');
};
Transaction.prototype._getMessageToSign = function (withEIP155) {
Transaction.prototype._getMessageToSign = function () {
var values = [
ethereumjs_util_1.bnToRlp(this.nonce),
ethereumjs_util_1.bnToRlp(this.gasPrice),
ethereumjs_util_1.bnToRlp(this.gasLimit),
ethereumjs_util_1.bnToUnpaddedBuffer(this.nonce),
ethereumjs_util_1.bnToUnpaddedBuffer(this.gasPrice),
ethereumjs_util_1.bnToUnpaddedBuffer(this.gasLimit),
this.to !== undefined ? this.to.buf : Buffer.from([]),
ethereumjs_util_1.bnToRlp(this.value),
ethereumjs_util_1.bnToUnpaddedBuffer(this.value),
this.data,
];
if (withEIP155) {
if (this.supports(types_1.Capability.EIP155ReplayProtection)) {
values.push(ethereumjs_util_1.toBuffer(this.common.chainIdBN()));

@@ -193,3 +208,3 @@ values.push(ethereumjs_util_1.unpadBuffer(ethereumjs_util_1.toBuffer(0)));

if (hashMessage === void 0) { hashMessage = true; }
var message = this._getMessageToSign(this._unsignedTxImplementsEIP155());
var message = this._getMessageToSign();
if (hashMessage) {

@@ -212,3 +227,3 @@ return ethereumjs_util_1.rlphash(message);

* This method can only be used for signed txs (it throws otherwise).
* Use `getMessageToSign()` to get a tx hash for the purpose of signing.
* Use {@link Transaction.getMessageToSign} to get a tx hash for the purpose of signing.
*/

@@ -222,4 +237,6 @@ Transaction.prototype.hash = function () {

Transaction.prototype.getMessageToVerifySignature = function () {
var withEIP155 = this._signedTxImplementsEIP155();
var message = this._getMessageToSign(withEIP155);
if (!this.isSigned()) {
throw Error('This transaction is not signed');
}
var message = this._getMessageToSign();
return ethereumjs_util_1.rlphash(message);

@@ -240,3 +257,3 @@ };

try {
return ethereumjs_util_1.ecrecover(msgHash, v, ethereumjs_util_1.bnToRlp(r), ethereumjs_util_1.bnToRlp(s), this._signedTxImplementsEIP155() ? this.common.chainIdBN() : undefined);
return ethereumjs_util_1.ecrecover(msgHash, v, ethereumjs_util_1.bnToUnpaddedBuffer(r), ethereumjs_util_1.bnToUnpaddedBuffer(s), this.supports(types_1.Capability.EIP155ReplayProtection) ? this.common.chainIdBN() : undefined);
}

@@ -252,3 +269,3 @@ catch (e) {

var vBN = new ethereumjs_util_1.BN(v);
if (this._unsignedTxImplementsEIP155()) {
if (this.supports(types_1.Capability.EIP155ReplayProtection)) {
vBN.iadd(this.common.chainIdBN().muln(2).addn(8));

@@ -322,2 +339,11 @@ }

};
/**
* @deprecated if you have called this internal method please use `tx.supports(Capabilities.EIP155ReplayProtection)` instead
*/
Transaction.prototype._unsignedTxImplementsEIP155 = function () {
return this.common.gteHardfork('spuriousDragon');
};
/**
* @deprecated if you have called this internal method please use `tx.supports(Capabilities.EIP155ReplayProtection)` instead
*/
Transaction.prototype._signedTxImplementsEIP155 = function () {

@@ -324,0 +350,0 @@ if (!this.isSigned()) {

@@ -9,7 +9,33 @@ /// <reference types="node" />

/**
* The options for initializing a Transaction.
* Can be used in conjunction with {@link Transaction.supports}
* to query on tx capabilities
*/
export declare enum Capability {
/**
* Tx supports EIP-155 replay protection
* See: [155](https://eips.ethereum.org/EIPS/eip-155) Replay Attack Protection EIP
*/
EIP155ReplayProtection = 155,
/**
* Tx supports EIP-1559 gas fee market mechansim
* See: [1559](https://eips.ethereum.org/EIPS/eip-1559) Fee Market EIP
*/
EIP1559FeeMarket = 1559,
/**
* Tx is a typed transaction as defined in EIP-2718
* See: [2718](https://eips.ethereum.org/EIPS/eip-2718) Transaction Type EIP
*/
EIP2718TypedTransaction = 2718,
/**
* Tx supports access list generation as defined in EIP-2930
* See: [2930](https://eips.ethereum.org/EIPS/eip-2930) Access Lists EIP
*/
EIP2930AccessLists = 2930
}
/**
* The options for initializing a {@link Transaction}.
*/
export interface TxOptions {
/**
* A Common object defining the chain and hardfork for the transaction.
* A {@link Common} object defining the chain and hardfork for the transaction.
*

@@ -19,3 +45,3 @@ * Object will be internally copied so that tx behavior don't incidentally

*
* Default: `Common` object set to `mainnet` and the default hardfork as defined in the `Common` class.
* Default: {@link Common} object set to `mainnet` and the default hardfork as defined in the {@link Common} class.
*

@@ -50,7 +76,7 @@ * Current default hardfork: `istanbul`

* Note that this also includes legacy txs which are
* referenced as `Transaction` for compatibility reasons.
* referenced as {@link Transaction} for compatibility reasons.
*/
export declare type TypedTransaction = Transaction | AccessListEIP2930Transaction | FeeMarketEIP1559Transaction;
/**
* Legacy Transaction Data
* Legacy {@link Transaction} Data
*/

@@ -100,3 +126,3 @@ export declare type TxData = {

/**
* Access list EIP2930 tx data.
* {@link AccessListEIP2930Transaction} data.
*/

@@ -114,3 +140,3 @@ export interface AccessListEIP2930TxData extends TxData {

/**
* Fee marked EIP1559 tx data.
* {@link FeeMarketEIP1559Transaction} data.
*/

@@ -132,11 +158,11 @@ export interface FeeMarketEIP1559TxData extends AccessListEIP2930TxData {

/**
* Buffer values array for a legacy transaction
* Buffer values array for a legacy {@link Transaction}
*/
export declare type TxValuesArray = Buffer[];
/**
* Buffer values array for an EIP2930 transaction
* Buffer values array for an {@link AccessListEIP2930Transaction}
*/
export declare type AccessListEIP2930ValuesArray = [Buffer, Buffer, Buffer, Buffer, Buffer, Buffer, Buffer, AccessListBuffer, Buffer?, Buffer?, Buffer?];
/**
* Buffer values array for an EIP1559 transaction
* Buffer values array for a {@link FeeMarketEIP1559Transaction}
*/

@@ -143,0 +169,0 @@ export declare type FeeMarketEIP1559ValuesArray = [Buffer, Buffer, Buffer, Buffer, Buffer, Buffer, Buffer, Buffer, AccessListBuffer, Buffer?, Buffer?, Buffer?];

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.N_DIV_2 = exports.isAccessList = exports.isAccessListBuffer = void 0;
exports.N_DIV_2 = exports.isAccessList = exports.isAccessListBuffer = exports.Capability = void 0;
var ethereumjs_util_1 = require("ethereumjs-util");
/**
* Can be used in conjunction with {@link Transaction.supports}
* to query on tx capabilities
*/
var Capability;
(function (Capability) {
/**
* Tx supports EIP-155 replay protection
* See: [155](https://eips.ethereum.org/EIPS/eip-155) Replay Attack Protection EIP
*/
Capability[Capability["EIP155ReplayProtection"] = 155] = "EIP155ReplayProtection";
/**
* Tx supports EIP-1559 gas fee market mechansim
* See: [1559](https://eips.ethereum.org/EIPS/eip-1559) Fee Market EIP
*/
Capability[Capability["EIP1559FeeMarket"] = 1559] = "EIP1559FeeMarket";
/**
* Tx is a typed transaction as defined in EIP-2718
* See: [2718](https://eips.ethereum.org/EIPS/eip-2718) Transaction Type EIP
*/
Capability[Capability["EIP2718TypedTransaction"] = 2718] = "EIP2718TypedTransaction";
/**
* Tx supports access list generation as defined in EIP-2930
* See: [2930](https://eips.ethereum.org/EIPS/eip-2930) Access Lists EIP
*/
Capability[Capability["EIP2930AccessLists"] = 2930] = "EIP2930AccessLists";
})(Capability = exports.Capability || (exports.Capability = {}));
function isAccessListBuffer(input) {

@@ -6,0 +33,0 @@ if (input.length === 0) {

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

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

@@ -26,2 +26,8 @@ * This base class will likely be subject to further

/**
* List of tx type defining EIPs,
* e.g. 1559 (fee market) and 2930 (access lists)
* for FeeMarketEIP1559Transaction objects
*/
protected activeCapabilities: number[];
/**
* The default chain the tx falls back to if no Common

@@ -44,3 +50,3 @@ * is provided and if the chain can't be derived from

/**
* Alias for `type`
* Alias for {@link BaseTransaction.type}
*

@@ -57,2 +63,19 @@ * @deprecated Use `type` instead

/**
* Checks if a tx type defining capability is active
* on a tx, for example the EIP-1559 fee market mechanism
* or the EIP-2930 access list feature.
*
* Note that this is different from the tx type itself,
* so EIP-2930 access lists can very well be active
* on an EIP-1559 tx for example.
*
* This method can be useful for feature checks if the
* tx type is unknown (e.g. when instantiated with
* the tx factory).
*
* See `Capabilites` in the `types` module for a reference
* on all supported capabilities.
*/
supports(capability: Capability): boolean;
/**
* Checks if the transaction has the minimum amount of gas required

@@ -125,3 +148,3 @@ * (DataFee + TxFee + Creation Fee).

*
* @param common - Common instance from tx options
* @param common - {@link Common} instance from tx options
* @param chainId - Chain ID from tx options (typed txs) or signature (legacy tx)

@@ -128,0 +151,0 @@ */

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

const ethereumjs_util_1 = require("ethereumjs-util");
const types_1 = require("./types");
/**

@@ -20,2 +21,8 @@ * This base class will likely be subject to further

/**
* List of tx type defining EIPs,
* e.g. 1559 (fee market) and 2930 (access lists)
* for FeeMarketEIP1559Transaction objects
*/
this.activeCapabilities = [];
/**
* The default chain the tx falls back to if no Common

@@ -59,3 +66,3 @@ * is provided and if the chain can't be derived from

/**
* Alias for `type`
* Alias for {@link BaseTransaction.type}
*

@@ -75,2 +82,21 @@ * @deprecated Use `type` instead

}
/**
* Checks if a tx type defining capability is active
* on a tx, for example the EIP-1559 fee market mechanism
* or the EIP-2930 access list feature.
*
* Note that this is different from the tx type itself,
* so EIP-2930 access lists can very well be active
* on an EIP-1559 tx for example.
*
* This method can be useful for feature checks if the
* tx type is unknown (e.g. when instantiated with
* the tx factory).
*
* See `Capabilites` in the `types` module for a reference
* on all supported capabilities.
*/
supports(capability) {
return this.activeCapabilities.includes(capability);
}
validate(stringError = false) {

@@ -165,5 +191,24 @@ const errors = [];

}
// Hack for the constellation that we have got a legacy tx after spuriousDragon with a non-EIP155 conforming signature
// and want to recreate a signature (where EIP155 should be applied)
// Leaving this hack lets the legacy.spec.ts -> sign(), verifySignature() test fail
// 2021-06-23
let hackApplied = false;
if (this.type === 0 &&
this.common.gteHardfork('spuriousDragon') &&
!this.supports(types_1.Capability.EIP155ReplayProtection)) {
this.activeCapabilities.push(types_1.Capability.EIP155ReplayProtection);
hackApplied = true;
}
const msgHash = this.getMessageToSign(true);
const { v, r, s } = ethereumjs_util_1.ecsign(msgHash, privateKey);
return this._processSignature(v, r, s);
const tx = this._processSignature(v, r, s);
// Hack part 2
if (hackApplied) {
const index = this.activeCapabilities.indexOf(types_1.Capability.EIP155ReplayProtection);
if (index > -1) {
this.activeCapabilities.splice(index, 1);
}
}
return tx;
}

@@ -175,3 +220,3 @@ /**

*
* @param common - Common instance from tx options
* @param common - {@link Common} instance from tx options
* @param chainId - Chain ID from tx options (typed txs) or signature (legacy tx)

@@ -178,0 +223,0 @@ */

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

@@ -65,3 +65,3 @@ import { AccessList, AccessListBuffer, FeeMarketEIP1559TxData, FeeMarketEIP1559ValuesArray, JsonTx, TxOptions } from './types';

* Instantiate a transaction from the serialized tx.
* (alias of `fromSerializedTx()`)
* (alias of {@link FeeMarketEIP1559Transaction.fromSerializedTx})
*

@@ -71,3 +71,3 @@ * Note: This means that the Buffer should start with 0x01.

* @deprecated this constructor alias is deprecated and will be removed
* in favor of the `fromSerializedTx()` constructor
* in favor of the {@link FeeMarketEIP1559Transaction.fromSerializedTx} constructor
*/

@@ -105,3 +105,3 @@ static fromRlpSerializedTx(serialized: Buffer, opts?: TxOptions): FeeMarketEIP1559Transaction;

*
* Use `serialize()` to add to block data for `Block.fromValuesArray()`.
* Use {@link FeeMarketEIP1559Transaction.serialize} to add to block data for {@link Block.fromValuesArray}.
*/

@@ -139,3 +139,3 @@ raw(): FeeMarketEIP1559ValuesArray;

* This method can only be used for signed txs (it throws otherwise).
* Use `getMessageToSign()` to get a tx hash for the purpose of signing.
* Use {@link FeeMarketEIP1559Transaction.getMessageToSign} to get a tx hash for the purpose of signing.
*/

@@ -142,0 +142,0 @@ hash(): Buffer;

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

}
this.activeCapabilities = this.activeCapabilities.concat([1559, 2718, 2930]);
// Populate the access list fields

@@ -123,3 +124,3 @@ const accessListData = util_1.AccessLists.getAccessListData(accessList !== null && accessList !== void 0 ? accessList : []);

* Instantiate a transaction from the serialized tx.
* (alias of `fromSerializedTx()`)
* (alias of {@link FeeMarketEIP1559Transaction.fromSerializedTx})
*

@@ -129,3 +130,3 @@ * Note: This means that the Buffer should start with 0x01.

* @deprecated this constructor alias is deprecated and will be removed
* in favor of the `fromSerializedTx()` constructor
* in favor of the {@link FeeMarketEIP1559Transaction.fromSerializedTx} constructor
*/

@@ -184,18 +185,18 @@ static fromRlpSerializedTx(serialized, opts = {}) {

*
* Use `serialize()` to add to block data for `Block.fromValuesArray()`.
* Use {@link FeeMarketEIP1559Transaction.serialize} to add to block data for {@link Block.fromValuesArray}.
*/
raw() {
return [
ethereumjs_util_1.bnToRlp(this.chainId),
ethereumjs_util_1.bnToRlp(this.nonce),
ethereumjs_util_1.bnToRlp(this.maxPriorityFeePerGas),
ethereumjs_util_1.bnToRlp(this.maxFeePerGas),
ethereumjs_util_1.bnToRlp(this.gasLimit),
ethereumjs_util_1.bnToUnpaddedBuffer(this.chainId),
ethereumjs_util_1.bnToUnpaddedBuffer(this.nonce),
ethereumjs_util_1.bnToUnpaddedBuffer(this.maxPriorityFeePerGas),
ethereumjs_util_1.bnToUnpaddedBuffer(this.maxFeePerGas),
ethereumjs_util_1.bnToUnpaddedBuffer(this.gasLimit),
this.to !== undefined ? this.to.buf : Buffer.from([]),
ethereumjs_util_1.bnToRlp(this.value),
ethereumjs_util_1.bnToUnpaddedBuffer(this.value),
this.data,
this.accessList,
this.v !== undefined ? ethereumjs_util_1.bnToRlp(this.v) : Buffer.from([]),
this.r !== undefined ? ethereumjs_util_1.bnToRlp(this.r) : Buffer.from([]),
this.s !== undefined ? ethereumjs_util_1.bnToRlp(this.s) : Buffer.from([]),
this.v !== undefined ? ethereumjs_util_1.bnToUnpaddedBuffer(this.v) : Buffer.from([]),
this.r !== undefined ? ethereumjs_util_1.bnToUnpaddedBuffer(this.r) : Buffer.from([]),
this.s !== undefined ? ethereumjs_util_1.bnToUnpaddedBuffer(this.s) : Buffer.from([]),
];

@@ -231,3 +232,3 @@ }

* This method can only be used for signed txs (it throws otherwise).
* Use `getMessageToSign()` to get a tx hash for the purpose of signing.
* Use {@link FeeMarketEIP1559Transaction.getMessageToSign} to get a tx hash for the purpose of signing.
*/

@@ -263,3 +264,3 @@ hash() {

return ethereumjs_util_1.ecrecover(msgHash, v.addn(27), // Recover the 27 which was stripped from ecsign
ethereumjs_util_1.bnToRlp(r), ethereumjs_util_1.bnToRlp(s));
ethereumjs_util_1.bnToUnpaddedBuffer(r), ethereumjs_util_1.bnToUnpaddedBuffer(s));
}

@@ -266,0 +267,0 @@ catch (e) {

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

@@ -64,3 +64,3 @@ import { AccessList, AccessListBuffer, AccessListEIP2930TxData, AccessListEIP2930ValuesArray, JsonTx, TxOptions } from './types';

* Instantiate a transaction from the serialized tx.
* (alias of `fromSerializedTx()`)
* (alias of {@link AccessListEIP2930Transaction.fromSerializedTx})
*

@@ -70,3 +70,3 @@ * Note: This means that the Buffer should start with 0x01.

* @deprecated this constructor alias is deprecated and will be removed
* in favor of the `fromSerializedTx()` constructor
* in favor of the {@link AccessListEIP2930Transaction.fromSerializedTx} constructor
*/

@@ -103,3 +103,3 @@ static fromRlpSerializedTx(serialized: Buffer, opts?: TxOptions): AccessListEIP2930Transaction;

*
* Use `serialize()` to add to block data for `Block.fromValuesArray()`.
* Use {@link AccessListEIP2930Transaction.serialize} to add to block data for {@link Block.fromValuesArray}.
*/

@@ -136,3 +136,3 @@ raw(): AccessListEIP2930ValuesArray;

* This method can only be used for signed txs (it throws otherwise).
* Use `getMessageToSign()` to get a tx hash for the purpose of signing.
* Use {@link AccessListEIP2930Transaction.getMessageToSign} to get a tx hash for the purpose of signing.
*/

@@ -139,0 +139,0 @@ hash(): Buffer;

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

}
this.activeCapabilities = this.activeCapabilities.concat([2718, 2930]);
// Populate the access list fields

@@ -117,3 +118,3 @@ const accessListData = util_1.AccessLists.getAccessListData(accessList !== null && accessList !== void 0 ? accessList : []);

* Instantiate a transaction from the serialized tx.
* (alias of `fromSerializedTx()`)
* (alias of {@link AccessListEIP2930Transaction.fromSerializedTx})
*

@@ -123,3 +124,3 @@ * Note: This means that the Buffer should start with 0x01.

* @deprecated this constructor alias is deprecated and will be removed
* in favor of the `fromSerializedTx()` constructor
* in favor of the {@link AccessListEIP2930Transaction.fromSerializedTx} constructor
*/

@@ -175,17 +176,17 @@ static fromRlpSerializedTx(serialized, opts = {}) {

*
* Use `serialize()` to add to block data for `Block.fromValuesArray()`.
* Use {@link AccessListEIP2930Transaction.serialize} to add to block data for {@link Block.fromValuesArray}.
*/
raw() {
return [
ethereumjs_util_1.bnToRlp(this.chainId),
ethereumjs_util_1.bnToRlp(this.nonce),
ethereumjs_util_1.bnToRlp(this.gasPrice),
ethereumjs_util_1.bnToRlp(this.gasLimit),
ethereumjs_util_1.bnToUnpaddedBuffer(this.chainId),
ethereumjs_util_1.bnToUnpaddedBuffer(this.nonce),
ethereumjs_util_1.bnToUnpaddedBuffer(this.gasPrice),
ethereumjs_util_1.bnToUnpaddedBuffer(this.gasLimit),
this.to !== undefined ? this.to.buf : Buffer.from([]),
ethereumjs_util_1.bnToRlp(this.value),
ethereumjs_util_1.bnToUnpaddedBuffer(this.value),
this.data,
this.accessList,
this.v !== undefined ? ethereumjs_util_1.bnToRlp(this.v) : Buffer.from([]),
this.r !== undefined ? ethereumjs_util_1.bnToRlp(this.r) : Buffer.from([]),
this.s !== undefined ? ethereumjs_util_1.bnToRlp(this.s) : Buffer.from([]),
this.v !== undefined ? ethereumjs_util_1.bnToUnpaddedBuffer(this.v) : Buffer.from([]),
this.r !== undefined ? ethereumjs_util_1.bnToUnpaddedBuffer(this.r) : Buffer.from([]),
this.s !== undefined ? ethereumjs_util_1.bnToUnpaddedBuffer(this.s) : Buffer.from([]),
];

@@ -234,3 +235,3 @@ }

* This method can only be used for signed txs (it throws otherwise).
* Use `getMessageToSign()` to get a tx hash for the purpose of signing.
* Use {@link AccessListEIP2930Transaction.getMessageToSign} to get a tx hash for the purpose of signing.
*/

@@ -266,3 +267,3 @@ hash() {

return ethereumjs_util_1.ecrecover(msgHash, yParity.addn(27), // Recover the 27 which was stripped from ecsign
ethereumjs_util_1.bnToRlp(r), ethereumjs_util_1.bnToRlp(s));
ethereumjs_util_1.bnToUnpaddedBuffer(r), ethereumjs_util_1.bnToUnpaddedBuffer(s));
}

@@ -269,0 +270,0 @@ catch (e) {

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

* Instantiate a transaction from the serialized tx.
* (alias of `fromSerializedTx()`)
* (alias of {@link Transaction.fromSerializedTx})
*
* @deprecated this constructor alias is deprecated and will be removed
* in favor of the `fromSerializedTx()` constructor
* in favor of the {@link Transaction.fromSerializedTx} constructor
*/

@@ -58,3 +58,3 @@ static fromRlpSerializedTx(serialized: Buffer, opts?: TxOptions): Transaction;

* for the signature parameters `v`, `r` and `s`. For an EIP-155 compliant
* representation have a look at the `getMessageToSign()` method.
* representation have a look at {@link Transaction.getMessageToSign}.
*/

@@ -69,6 +69,5 @@ raw(): TxValuesArray;

* for the signature parameters `v`, `r` and `s` for encoding. For an
* EIP-155 compliant representation use the `getMessageToSign()` method.
* EIP-155 compliant representation use {@link Transaction.getMessageToSign}.
*/
serialize(): Buffer;
private _unsignedTxImplementsEIP155;
private _getMessageToSign;

@@ -100,3 +99,3 @@ /**

* This method can only be used for signed txs (it throws otherwise).
* Use `getMessageToSign()` to get a tx hash for the purpose of signing.
* Use {@link Transaction.getMessageToSign} to get a tx hash for the purpose of signing.
*/

@@ -124,3 +123,10 @@ hash(): Buffer;

private _validateTxV;
/**
* @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;
}

@@ -24,2 +24,20 @@ "use strict";

this._validateCannotExceedMaxInteger({ gasPrice: this.gasPrice });
if (this.common.gteHardfork('spuriousDragon')) {
if (!this.isSigned()) {
this.activeCapabilities.push(types_1.Capability.EIP155ReplayProtection);
}
else {
// 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);
// v and chain ID meet EIP-155 conditions
if (v.eq(chainIdDoubled.addn(35)) || v.eq(chainIdDoubled.addn(36))) {
this.activeCapabilities.push(types_1.Capability.EIP155ReplayProtection);
}
}
}
const freeze = (_a = opts === null || opts === void 0 ? void 0 : opts.freeze) !== null && _a !== void 0 ? _a : true;

@@ -55,6 +73,6 @@ if (freeze) {

* Instantiate a transaction from the serialized tx.
* (alias of `fromSerializedTx()`)
* (alias of {@link Transaction.fromSerializedTx})
*
* @deprecated this constructor alias is deprecated and will be removed
* in favor of the `fromSerializedTx()` constructor
* in favor of the {@link Transaction.fromSerializedTx} constructor
*/

@@ -95,15 +113,15 @@ static fromRlpSerializedTx(serialized, opts = {}) {

* for the signature parameters `v`, `r` and `s`. For an EIP-155 compliant
* representation have a look at the `getMessageToSign()` method.
* representation have a look at {@link Transaction.getMessageToSign}.
*/
raw() {
return [
ethereumjs_util_1.bnToRlp(this.nonce),
ethereumjs_util_1.bnToRlp(this.gasPrice),
ethereumjs_util_1.bnToRlp(this.gasLimit),
ethereumjs_util_1.bnToUnpaddedBuffer(this.nonce),
ethereumjs_util_1.bnToUnpaddedBuffer(this.gasPrice),
ethereumjs_util_1.bnToUnpaddedBuffer(this.gasLimit),
this.to !== undefined ? this.to.buf : Buffer.from([]),
ethereumjs_util_1.bnToRlp(this.value),
ethereumjs_util_1.bnToUnpaddedBuffer(this.value),
this.data,
this.v !== undefined ? ethereumjs_util_1.bnToRlp(this.v) : Buffer.from([]),
this.r !== undefined ? ethereumjs_util_1.bnToRlp(this.r) : Buffer.from([]),
this.s !== undefined ? ethereumjs_util_1.bnToRlp(this.s) : Buffer.from([]),
this.v !== undefined ? ethereumjs_util_1.bnToUnpaddedBuffer(this.v) : Buffer.from([]),
this.r !== undefined ? ethereumjs_util_1.bnToUnpaddedBuffer(this.r) : Buffer.from([]),
this.s !== undefined ? ethereumjs_util_1.bnToUnpaddedBuffer(this.s) : Buffer.from([]),
];

@@ -118,3 +136,3 @@ }

* for the signature parameters `v`, `r` and `s` for encoding. For an
* EIP-155 compliant representation use the `getMessageToSign()` method.
* EIP-155 compliant representation use {@link Transaction.getMessageToSign}.
*/

@@ -124,15 +142,12 @@ serialize() {

}
_unsignedTxImplementsEIP155() {
return this.common.gteHardfork('spuriousDragon');
}
_getMessageToSign(withEIP155) {
_getMessageToSign() {
const values = [
ethereumjs_util_1.bnToRlp(this.nonce),
ethereumjs_util_1.bnToRlp(this.gasPrice),
ethereumjs_util_1.bnToRlp(this.gasLimit),
ethereumjs_util_1.bnToUnpaddedBuffer(this.nonce),
ethereumjs_util_1.bnToUnpaddedBuffer(this.gasPrice),
ethereumjs_util_1.bnToUnpaddedBuffer(this.gasLimit),
this.to !== undefined ? this.to.buf : Buffer.from([]),
ethereumjs_util_1.bnToRlp(this.value),
ethereumjs_util_1.bnToUnpaddedBuffer(this.value),
this.data,
];
if (withEIP155) {
if (this.supports(types_1.Capability.EIP155ReplayProtection)) {
values.push(ethereumjs_util_1.toBuffer(this.common.chainIdBN()));

@@ -145,3 +160,3 @@ values.push(ethereumjs_util_1.unpadBuffer(ethereumjs_util_1.toBuffer(0)));

getMessageToSign(hashMessage = true) {
const message = this._getMessageToSign(this._unsignedTxImplementsEIP155());
const message = this._getMessageToSign();
if (hashMessage) {

@@ -164,3 +179,3 @@ return ethereumjs_util_1.rlphash(message);

* This method can only be used for signed txs (it throws otherwise).
* Use `getMessageToSign()` to get a tx hash for the purpose of signing.
* Use {@link Transaction.getMessageToSign} to get a tx hash for the purpose of signing.
*/

@@ -174,4 +189,6 @@ hash() {

getMessageToVerifySignature() {
const withEIP155 = this._signedTxImplementsEIP155();
const message = this._getMessageToSign(withEIP155);
if (!this.isSigned()) {
throw Error('This transaction is not signed');
}
const message = this._getMessageToSign();
return ethereumjs_util_1.rlphash(message);

@@ -192,3 +209,3 @@ }

try {
return ethereumjs_util_1.ecrecover(msgHash, v, ethereumjs_util_1.bnToRlp(r), ethereumjs_util_1.bnToRlp(s), this._signedTxImplementsEIP155() ? this.common.chainIdBN() : undefined);
return ethereumjs_util_1.ecrecover(msgHash, v, ethereumjs_util_1.bnToUnpaddedBuffer(r), ethereumjs_util_1.bnToUnpaddedBuffer(s), this.supports(types_1.Capability.EIP155ReplayProtection) ? this.common.chainIdBN() : undefined);
}

@@ -204,3 +221,3 @@ catch (e) {

const vBN = new ethereumjs_util_1.BN(v);
if (this._unsignedTxImplementsEIP155()) {
if (this.supports(types_1.Capability.EIP155ReplayProtection)) {
vBN.iadd(this.common.chainIdBN().muln(2).addn(8));

@@ -274,2 +291,11 @@ }

}
/**
* @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() {

@@ -276,0 +302,0 @@ if (!this.isSigned()) {

@@ -9,7 +9,33 @@ /// <reference types="node" />

/**
* The options for initializing a Transaction.
* Can be used in conjunction with {@link Transaction.supports}
* to query on tx capabilities
*/
export declare enum Capability {
/**
* Tx supports EIP-155 replay protection
* See: [155](https://eips.ethereum.org/EIPS/eip-155) Replay Attack Protection EIP
*/
EIP155ReplayProtection = 155,
/**
* Tx supports EIP-1559 gas fee market mechansim
* See: [1559](https://eips.ethereum.org/EIPS/eip-1559) Fee Market EIP
*/
EIP1559FeeMarket = 1559,
/**
* Tx is a typed transaction as defined in EIP-2718
* See: [2718](https://eips.ethereum.org/EIPS/eip-2718) Transaction Type EIP
*/
EIP2718TypedTransaction = 2718,
/**
* Tx supports access list generation as defined in EIP-2930
* See: [2930](https://eips.ethereum.org/EIPS/eip-2930) Access Lists EIP
*/
EIP2930AccessLists = 2930
}
/**
* The options for initializing a {@link Transaction}.
*/
export interface TxOptions {
/**
* A Common object defining the chain and hardfork for the transaction.
* A {@link Common} object defining the chain and hardfork for the transaction.
*

@@ -19,3 +45,3 @@ * Object will be internally copied so that tx behavior don't incidentally

*
* Default: `Common` object set to `mainnet` and the default hardfork as defined in the `Common` class.
* Default: {@link Common} object set to `mainnet` and the default hardfork as defined in the {@link Common} class.
*

@@ -50,7 +76,7 @@ * Current default hardfork: `istanbul`

* Note that this also includes legacy txs which are
* referenced as `Transaction` for compatibility reasons.
* referenced as {@link Transaction} for compatibility reasons.
*/
export declare type TypedTransaction = Transaction | AccessListEIP2930Transaction | FeeMarketEIP1559Transaction;
/**
* Legacy Transaction Data
* Legacy {@link Transaction} Data
*/

@@ -100,3 +126,3 @@ export declare type TxData = {

/**
* Access list EIP2930 tx data.
* {@link AccessListEIP2930Transaction} data.
*/

@@ -114,3 +140,3 @@ export interface AccessListEIP2930TxData extends TxData {

/**
* Fee marked EIP1559 tx data.
* {@link FeeMarketEIP1559Transaction} data.
*/

@@ -132,11 +158,11 @@ export interface FeeMarketEIP1559TxData extends AccessListEIP2930TxData {

/**
* Buffer values array for a legacy transaction
* Buffer values array for a legacy {@link Transaction}
*/
export declare type TxValuesArray = Buffer[];
/**
* Buffer values array for an EIP2930 transaction
* Buffer values array for an {@link AccessListEIP2930Transaction}
*/
export declare type AccessListEIP2930ValuesArray = [Buffer, Buffer, Buffer, Buffer, Buffer, Buffer, Buffer, AccessListBuffer, Buffer?, Buffer?, Buffer?];
/**
* Buffer values array for an EIP1559 transaction
* Buffer values array for a {@link FeeMarketEIP1559Transaction}
*/

@@ -143,0 +169,0 @@ export declare type FeeMarketEIP1559ValuesArray = [Buffer, Buffer, Buffer, Buffer, Buffer, Buffer, Buffer, Buffer, AccessListBuffer, Buffer?, Buffer?, Buffer?];

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.N_DIV_2 = exports.isAccessList = exports.isAccessListBuffer = void 0;
exports.N_DIV_2 = exports.isAccessList = exports.isAccessListBuffer = exports.Capability = void 0;
const ethereumjs_util_1 = require("ethereumjs-util");
/**
* Can be used in conjunction with {@link Transaction.supports}
* to query on tx capabilities
*/
var Capability;
(function (Capability) {
/**
* Tx supports EIP-155 replay protection
* See: [155](https://eips.ethereum.org/EIPS/eip-155) Replay Attack Protection EIP
*/
Capability[Capability["EIP155ReplayProtection"] = 155] = "EIP155ReplayProtection";
/**
* Tx supports EIP-1559 gas fee market mechansim
* See: [1559](https://eips.ethereum.org/EIPS/eip-1559) Fee Market EIP
*/
Capability[Capability["EIP1559FeeMarket"] = 1559] = "EIP1559FeeMarket";
/**
* Tx is a typed transaction as defined in EIP-2718
* See: [2718](https://eips.ethereum.org/EIPS/eip-2718) Transaction Type EIP
*/
Capability[Capability["EIP2718TypedTransaction"] = 2718] = "EIP2718TypedTransaction";
/**
* Tx supports access list generation as defined in EIP-2930
* See: [2930](https://eips.ethereum.org/EIPS/eip-2930) Access Lists EIP
*/
Capability[Capability["EIP2930AccessLists"] = 2930] = "EIP2930AccessLists";
})(Capability = exports.Capability || (exports.Capability = {}));
function isAccessListBuffer(input) {

@@ -6,0 +33,0 @@ if (input.length === 0) {

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

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

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

@@ -20,12 +21,12 @@ "main": "dist/index.js",

"scripts": {
"build": "ethereumjs-config-ts-build",
"build": "../../config/cli/ts-build.sh",
"prepublishOnly": "npm run clean && npm run build && npm run test",
"clean": "rm -Rf ./dist && rm -Rf ./dist.browser",
"coverage": "ethereumjs-config-coverage",
"coverage": "../../config/cli/coverage.sh",
"docs:build": "typedoc --options typedoc.js",
"format": "ethereumjs-config-format",
"format:fix": "ethereumjs-config-format-fix",
"tsc": "ethereumjs-config-tsc",
"lint": "ethereumjs-config-lint",
"lint:fix": "ethereumjs-config-lint-fix",
"tsc": "../../config/cli/ts-compile.sh",
"lint": "../../config/cli/lint.sh",
"lint:fix": "../../config/cli/lint-fix.sh",
"test": "npm run test:node && npm run test:browser",

@@ -37,18 +38,11 @@ "test:node": "tape -r ts-node/register ./test/index.ts",

"dependencies": {
"@ethereumjs/common": "^2.3.1",
"ethereumjs-util": "^7.0.10"
"@ethereumjs/common": "^2.4.0",
"ethereumjs-util": "^7.1.0"
},
"devDependencies": {
"@ethereumjs/config-coverage": "^2.0.0",
"@ethereumjs/config-typescript": "^2.0.0",
"@ethereumjs/eslint-config-defaults": "^2.0.0",
"@types/minimist": "^1.2.0",
"@types/node": "^11.13.4",
"@types/tape": "^4.13.0",
"@typescript-eslint/eslint-plugin": "^4.1.1",
"browserify": "^16.5.1",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-implicit-dependencies": "^1.0.4",
"istanbul": "^0.4.1",
"karma": "^6.3.2",

@@ -65,5 +59,3 @@ "karma-browserify": "^8.0.0",

"ts-node": "^8.8.2",
"tslint": "^5.16.0",
"typedoc": "^0.20.34",
"typedoc-plugin-markdown": "^3.6.0",
"typescript": "^3.9.3"

@@ -70,0 +62,0 @@ },

@@ -20,4 +20,6 @@ # @ethereumjs/tx

## Introduction
## Setup
### Static Constructor Methods
To instantiate a tx it is not recommended to use the constructor directly. Instead each tx type comes with the following set of static constructor methods which helps on instantiation depending on the input data format:

@@ -33,2 +35,20 @@

### Chain and Hardfork Support
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`
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."
Supported Hardforks:
Hardfork | Introduced | Description
--- | --- | ---
`london` | `v3.2.0` | `EIP-1559` Transactions
`berlin` | `v3.1.0` | `EIP-2718` Typed Transactions, Optional Access Lists Tx Type `EIP-2930`
`muirGlacier` | `v2.1.2` | -
`istanbul` | `v2.1.1` | Support for reduced non-zero call data gas prices ([EIP-2028](https://eips.ethereum.org/EIPS/eip-2028))
`spuriousDragon` | `v2.0.0` | `EIP-155` replay protection (disable by setting HF pre-`spuriousDragon`)
## Transaction Types

@@ -167,2 +187,6 @@

const tx = TransactionFactory.fromTxData(txData, { common })
if (tx.supports(Capability.EIP2930AccessLists)) {
// Do something which only makes sense for txs with support for access lists
}
```

@@ -178,4 +202,52 @@

## Fake Transaction
## Sending a Transaction
### L2 Support
This library has been tested to work with various L2 networks (`v3.3.0`+). All predefined supported custom chains introduced with `Common` `v2.4.0` or higher are supported, the following is a simple example to send a tx to the xDai chain:
```typescript
import { Transaction } from '@ethereumjs/tx'
import Common from '@ethereumjs/common'
const from = 'PUBLIC_KEY'
const PRIV_KEY = process.argv[2]
const to = 'DESTINATION_ETHEREUM_ADDRESS'
const common = Common.custom(CustomChain.xDaiChain)
const txData = {
from,
nonce: 0,
gasPrice: 1000000000,
gasLimit: 21000,
to,
value: 1,
}
const tx = Transaction.fromTxData(txData, { common })
const signedTx = tx.sign(Buffer.from(PRIV_KEY, 'hex'))
```
The following L2 networks have been tested to work with `@ethereumjs/tx`, see usage examples as well as some notes on pecularities in the issues linked below:
| L2 Network | Common name | Issue |
|---|---|---|
| Arbitrum Rinkeby Testnet | `CustomChain.ArbitrumRinkebyTestnet` | [#1290](https://github.com/ethereumjs/ethereumjs-monorepo/issues/1290) |
| Polygon Mainnet | `CustomChain.PolygonMainnet` | [#1289](https://github.com/ethereumjs/ethereumjs-monorepo/issues/1289) |
| Polygon Mumbai Testnet | `CustomChain.PolygonMumbai` | [#1289](https://github.com/ethereumjs/ethereumjs-monorepo/issues/1289) |
| xDai Chain | `Common.xDaiChain` | [#1323](https://github.com/ethereumjs/ethereumjs-monorepo/issues/1323) |
For a non-predefined custom chain it is also possible to just provide a chain ID as well as other parameters to `Common`:
```typescript
const common = Common.custom({ chainId: 1234 })
```
## Special Topics
### Fake Transaction
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:

@@ -201,22 +273,2 @@

# SETUP
## Chain and Hardfork Support
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`
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."
### Supported Hardforks
Hardfork | Introduced | Description
--- | --- | ---
`london` | `v3.2.0` | `EIP-1559` Transactions
`berlin` | `v3.1.0` | `EIP-2718` Typed Transactions, Optional Access Lists Tx Type `EIP-2930`
`muirGlacier` | `v2.1.2` | -
`istanbul` | `v2.1.1` | Support for reduced non-zero call data gas prices ([EIP-2028](https://eips.ethereum.org/EIPS/eip-2028))
`spuriousDragon` | `v2.0.0` | `EIP-155` replay protection (disable by setting HF pre-`spuriousDragon`)
# API

@@ -223,0 +275,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc