Socket
Socket
Sign inDemoInstall

@ethereumjs/tx

Package Overview
Dependencies
Maintainers
6
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ethereumjs/tx - npm Package Compare versions

Comparing version 3.0.0-beta.1 to 3.0.0-beta.2

7

CHANGELOG.md

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

## 3.0.0-beta.2 - 2020-11-12
- Added `freeze` option to allow for transaction freeze deactivation (e.g. to allow for subclassing tx and adding additional parameters), see PR [#941](https://github.com/ethereumjs/ethereumjs-vm/pull/941)
- **Breaking:** Reworked constructor to take in data as a `TxData` typed dictionary instead of single values, the `Tx.fromTxData()` factory method becomes an alias for the constructor with this change, see PR [#944](https://github.com/ethereumjs/ethereumjs-vm/pull/944)
## 3.0.0-beta.1 - 2020-10-22

@@ -90,3 +95,3 @@

**Breaking:** The default HF on the library has been updated from `petersburg` to `instanbul`, see PR [#906](https://github.com/ethereumjs/ethereumjs-vm/pull/906).
**Breaking:** The default HF on the library has been updated from `petersburg` to `istanbul`, see PR [#906](https://github.com/ethereumjs/ethereumjs-vm/pull/906).
The HF setting is now automatically taken from the HF set for `Common.DEAULT_HARDFORK`,

@@ -93,0 +98,0 @@ see PR [#863](https://github.com/ethereumjs/ethereumjs-vm/pull/863).

6

dist.browser/transaction.d.ts

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

*/
constructor(nonce: BN, gasPrice: BN, gasLimit: BN, to: Address | undefined, value: BN, data: Buffer, v?: BN, r?: BN, s?: BN, opts?: TxOptions);
constructor(txData: TxData, opts?: TxOptions);
/**

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

/**
* Validates the signature and checks to see if it has enough gas.
* Validates the signature and checks if
* the transaction has the minimum amount of gas required
* (DataFee + TxFee + Creation Fee).
*/

@@ -83,0 +85,0 @@ validate(): boolean;

@@ -48,15 +48,26 @@ "use strict";

*/
function Transaction(nonce, gasPrice, gasLimit, to, value, data, v, r, s, opts) {
function Transaction(txData, opts) {
var e_1, _a;
var _b;
var nonce = txData.nonce, gasPrice = txData.gasPrice, gasLimit = txData.gasLimit, to = txData.to, value = txData.value, data = txData.data, v = txData.v, r = txData.r, s = txData.s;
this.nonce = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(nonce));
this.gasPrice = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(gasPrice));
this.gasLimit = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(gasLimit));
this.to = to ? new ethereumjs_util_1.Address(ethereumjs_util_1.toBuffer(to)) : undefined;
this.value = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(value));
this.data = ethereumjs_util_1.toBuffer(data);
this.v = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(v));
this.r = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(r));
this.s = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(s));
var validateCannotExceedMaxInteger = {
nonce: nonce,
gasPrice: gasPrice,
gasLimit: gasLimit,
value: value,
r: r,
s: s,
nonce: this.nonce,
gasPrice: this.gasPrice,
gasLimit: this.gasLimit,
value: this.value,
r: this.r,
s: this.s,
};
try {
for (var _b = __values(Object.entries(validateCannotExceedMaxInteger)), _c = _b.next(); !_c.done; _c = _b.next()) {
var _d = __read(_c.value, 2), key = _d[0], value_1 = _d[1];
for (var _c = __values(Object.entries(validateCannotExceedMaxInteger)), _d = _c.next(); !_d.done; _d = _c.next()) {
var _e = __read(_d.value, 2), key = _e[0], value_1 = _e[1];
if (value_1 && value_1.gt(ethereumjs_util_1.MAX_INTEGER)) {

@@ -70,3 +81,3 @@ throw new Error(key + " cannot exceed MAX_INTEGER, given " + value_1);

try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
}

@@ -82,17 +93,10 @@ finally { if (e_1) throw e_1.error; }

}
this._validateTxV(v);
this.nonce = nonce;
this.gasPrice = gasPrice;
this.gasLimit = gasLimit;
this.to = to;
this.value = value;
this.data = data;
this.v = v;
this.r = r;
this.s = s;
Object.freeze(this);
this._validateTxV(this.v);
var freeze = (_b = opts === null || opts === void 0 ? void 0 : opts.freeze) !== null && _b !== void 0 ? _b : true;
if (freeze) {
Object.freeze(this);
}
}
Transaction.fromTxData = function (txData, opts) {
var nonce = txData.nonce, gasLimit = txData.gasLimit, gasPrice = txData.gasPrice, to = txData.to, value = txData.value, data = txData.data, v = txData.v, r = txData.r, s = txData.s;
return new Transaction(new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(nonce)), new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(gasPrice)), new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(gasLimit)), to ? new ethereumjs_util_1.Address(ethereumjs_util_1.toBuffer(to)) : undefined, new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(value)), ethereumjs_util_1.toBuffer(data), new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(v)), new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(r)), new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(s)), opts);
return new Transaction(txData, opts);
};

@@ -111,3 +115,13 @@ Transaction.fromRlpSerializedTx = function (serialized, opts) {

var _a = __read(values, 9), nonce = _a[0], gasPrice = _a[1], gasLimit = _a[2], to = _a[3], value = _a[4], data = _a[5], v = _a[6], r = _a[7], s = _a[8];
return new Transaction(new ethereumjs_util_1.BN(nonce), new ethereumjs_util_1.BN(gasPrice), new ethereumjs_util_1.BN(gasLimit), to && to.length > 0 ? new ethereumjs_util_1.Address(to) : undefined, new ethereumjs_util_1.BN(value), data || buffer_1.Buffer.from([]), v ? new ethereumjs_util_1.BN(v) : undefined, r ? new ethereumjs_util_1.BN(r) : undefined, s ? new ethereumjs_util_1.BN(s) : undefined, opts);
return new Transaction({
nonce: new ethereumjs_util_1.BN(nonce),
gasPrice: new ethereumjs_util_1.BN(gasPrice),
gasLimit: new ethereumjs_util_1.BN(gasLimit),
to: to && to.length > 0 ? new ethereumjs_util_1.Address(to) : undefined,
value: new ethereumjs_util_1.BN(value),
data: data || buffer_1.Buffer.from([]),
v: v ? new ethereumjs_util_1.BN(v) : undefined,
r: r ? new ethereumjs_util_1.BN(r) : undefined,
s: s ? new ethereumjs_util_1.BN(s) : undefined,
}, opts);
};

@@ -180,3 +194,5 @@ /**

try {
return ethereumjs_util_1.unpadBuffer(this.getSenderPublicKey()).length !== 0;
// Main signature verification is done in `getSenderPublicKey()`
var publicKey = this.getSenderPublicKey();
return ethereumjs_util_1.unpadBuffer(publicKey).length !== 0;
}

@@ -211,3 +227,13 @@ catch (e) {

};
return new Transaction(this.nonce, this.gasPrice, this.gasLimit, this.to, this.value, this.data, new ethereumjs_util_1.BN(v), new ethereumjs_util_1.BN(r), new ethereumjs_util_1.BN(s), opts);
return new Transaction({
nonce: this.nonce,
gasPrice: this.gasPrice,
gasLimit: this.gasLimit,
to: this.to,
value: this.value,
data: this.data,
v: new ethereumjs_util_1.BN(v),
r: new ethereumjs_util_1.BN(r),
s: new ethereumjs_util_1.BN(s),
}, opts);
};

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

@@ -15,2 +15,13 @@ import { AddressLike, BNLike, BufferLike } from 'ethereumjs-util';

common?: Common;
/**
* A transaction object by default gets frozen along initialization. This gives you
* strong additional security guarantees on the consistency of the tx parameters.
*
* If you need to deactivate the tx freeze - e.g. because you want to subclass tx and
* add aditional properties - it is strongly encouraged that you do the freeze yourself
* within your code instead.
*
* Default: true
*/
freeze?: boolean;
}

@@ -17,0 +28,0 @@ /**

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

*/
constructor(nonce: BN, gasPrice: BN, gasLimit: BN, to: Address | undefined, value: BN, data: Buffer, v?: BN, r?: BN, s?: BN, opts?: TxOptions);
constructor(txData: TxData, opts?: TxOptions);
/**

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

/**
* Validates the signature and checks to see if it has enough gas.
* Validates the signature and checks if
* the transaction has the minimum amount of gas required
* (DataFee + TxFee + Creation Fee).
*/

@@ -83,0 +85,0 @@ validate(): boolean;

@@ -21,10 +21,21 @@ "use strict";

*/
constructor(nonce, gasPrice, gasLimit, to, value, data, v, r, s, opts) {
constructor(txData, opts) {
var _a;
const { nonce, gasPrice, gasLimit, to, value, data, v, r, s } = txData;
this.nonce = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(nonce));
this.gasPrice = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(gasPrice));
this.gasLimit = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(gasLimit));
this.to = to ? new ethereumjs_util_1.Address(ethereumjs_util_1.toBuffer(to)) : undefined;
this.value = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(value));
this.data = ethereumjs_util_1.toBuffer(data);
this.v = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(v));
this.r = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(r));
this.s = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(s));
const validateCannotExceedMaxInteger = {
nonce,
gasPrice,
gasLimit,
value,
r,
s,
nonce: this.nonce,
gasPrice: this.gasPrice,
gasLimit: this.gasLimit,
value: this.value,
r: this.r,
s: this.s,
};

@@ -43,17 +54,10 @@ for (const [key, value] of Object.entries(validateCannotExceedMaxInteger)) {

}
this._validateTxV(v);
this.nonce = nonce;
this.gasPrice = gasPrice;
this.gasLimit = gasLimit;
this.to = to;
this.value = value;
this.data = data;
this.v = v;
this.r = r;
this.s = s;
Object.freeze(this);
this._validateTxV(this.v);
const freeze = (_a = opts === null || opts === void 0 ? void 0 : opts.freeze) !== null && _a !== void 0 ? _a : true;
if (freeze) {
Object.freeze(this);
}
}
static fromTxData(txData, opts) {
const { nonce, gasLimit, gasPrice, to, value, data, v, r, s } = txData;
return new Transaction(new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(nonce)), new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(gasPrice)), new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(gasLimit)), to ? new ethereumjs_util_1.Address(ethereumjs_util_1.toBuffer(to)) : undefined, new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(value)), ethereumjs_util_1.toBuffer(data), new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(v)), new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(r)), new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(s)), opts);
return new Transaction(txData, opts);
}

@@ -72,3 +76,13 @@ static fromRlpSerializedTx(serialized, opts) {

const [nonce, gasPrice, gasLimit, to, value, data, v, r, s] = values;
return new Transaction(new ethereumjs_util_1.BN(nonce), new ethereumjs_util_1.BN(gasPrice), new ethereumjs_util_1.BN(gasLimit), to && to.length > 0 ? new ethereumjs_util_1.Address(to) : undefined, new ethereumjs_util_1.BN(value), data || buffer_1.Buffer.from([]), v ? new ethereumjs_util_1.BN(v) : undefined, r ? new ethereumjs_util_1.BN(r) : undefined, s ? new ethereumjs_util_1.BN(s) : undefined, opts);
return new Transaction({
nonce: new ethereumjs_util_1.BN(nonce),
gasPrice: new ethereumjs_util_1.BN(gasPrice),
gasLimit: new ethereumjs_util_1.BN(gasLimit),
to: to && to.length > 0 ? new ethereumjs_util_1.Address(to) : undefined,
value: new ethereumjs_util_1.BN(value),
data: data || buffer_1.Buffer.from([]),
v: v ? new ethereumjs_util_1.BN(v) : undefined,
r: r ? new ethereumjs_util_1.BN(r) : undefined,
s: s ? new ethereumjs_util_1.BN(s) : undefined,
}, opts);
}

@@ -141,3 +155,5 @@ /**

try {
return ethereumjs_util_1.unpadBuffer(this.getSenderPublicKey()).length !== 0;
// Main signature verification is done in `getSenderPublicKey()`
const publicKey = this.getSenderPublicKey();
return ethereumjs_util_1.unpadBuffer(publicKey).length !== 0;
}

@@ -172,3 +188,13 @@ catch (e) {

};
return new Transaction(this.nonce, this.gasPrice, this.gasLimit, this.to, this.value, this.data, new ethereumjs_util_1.BN(v), new ethereumjs_util_1.BN(r), new ethereumjs_util_1.BN(s), opts);
return new Transaction({
nonce: this.nonce,
gasPrice: this.gasPrice,
gasLimit: this.gasLimit,
to: this.to,
value: this.value,
data: this.data,
v: new ethereumjs_util_1.BN(v),
r: new ethereumjs_util_1.BN(r),
s: new ethereumjs_util_1.BN(s),
}, opts);
}

@@ -175,0 +201,0 @@ /**

@@ -15,2 +15,13 @@ import { AddressLike, BNLike, BufferLike } from 'ethereumjs-util';

common?: Common;
/**
* A transaction object by default gets frozen along initialization. This gives you
* strong additional security guarantees on the consistency of the tx parameters.
*
* If you need to deactivate the tx freeze - e.g. because you want to subclass tx and
* add aditional properties - it is strongly encouraged that you do the freeze yourself
* within your code instead.
*
* Default: true
*/
freeze?: boolean;
}

@@ -17,0 +28,0 @@ /**

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

@@ -34,3 +34,3 @@ "main": "dist/index.js",

"dependencies": {
"@ethereumjs/common": "2.0.0-beta.1",
"@ethereumjs/common": "2.0.0-beta.2",
"ethereumjs-util": "^7.0.7"

@@ -37,0 +37,0 @@ },

@@ -9,2 +9,4 @@ # @ethereumjs/tx

Note: this `README` reflects the state of the library from `v3.0.0` onwards. See `README` from the [standalone repository](https://github.com/ethereumjs/ethereumjs-tx) for an introduction on the last preceeding release.
# INSTALL

@@ -30,3 +32,3 @@

const commmon = new Common({ chain: 'mainnet', hardfork: 'petersburg' })
const commmon = new Common({ chain: 'mainnet' })
const tx = Transaction.fromTxData(txParams, { common })

@@ -44,2 +46,4 @@

Properties of a `Transaction` object are frozen with `Object.freeze()` which gives you enhanced security and consistency properties when working with the instantiated object. This behavior can be modified using the `freeze` option in the constructor if needed.
## Fake Transaction

@@ -69,3 +73,3 @@

The `Transaction` constructor receives a parameter of an [`@ethereumjs/common`](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common) object that lets you specify the chain and hardfork to be used. By default, `mainnet` and `petersburg` will be used.
The `Transaction` constructor receives a parameter of an [`@ethereumjs/common`](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common) object that lets you specify the chain and hardfork to be used. By default, `mainnet` and `istanbul` will be used.

@@ -72,0 +76,0 @@ ## MuirGlacier Support

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