Socket
Socket
Sign inDemoInstall

@ethereumjs/tx

Package Overview
Dependencies
44
Maintainers
3
Versions
37
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.3.2 to 3.4.0

20

dist.browser/baseTransaction.d.ts

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

hash: Buffer | undefined;
dataFee?: {
value: BN;
hardfork: string | Hardfork;
};
}

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

}, bits?: number): void;
/**
* Return a compact error string representation of the object
*/
abstract errorStr(): string;
/**
* Internal helper function to create an annotated error message
*
* @param msg Base error message
* @hidden
*/
protected abstract _errorMsg(msg: string): string;
/**
* Returns the shared error postfix part for _error() method
* tx type implementations.
*/
protected _getSharedErrorPostfix(): string;
}
export {};

46

dist.browser/baseTransaction.js

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

hash: undefined,
dataFee: undefined,
};

@@ -241,3 +242,4 @@ /**

if (privateKey.length !== 32) {
throw new Error('Private key must be 32 bytes in length.');
var msg = this._errorMsg('Private key must be 32 bytes in length.');
throw new Error(msg);
}

@@ -282,3 +284,4 @@ // Hack for the constellation that we have got a legacy tx after spuriousDragon with a non-EIP155 conforming signature

if (!common.chainIdBN().eq(chainIdBN)) {
throw new Error('The chain ID does not match the chain ID of Common');
var msg = this._errorMsg('The chain ID does not match the chain ID of Common');
throw new Error(msg);
}

@@ -320,3 +323,4 @@ // Common provided, chain ID does match

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);
var msg = this._errorMsg(key + " cannot exceed MAX_INTEGER, given " + value);
throw new Error(msg);
}

@@ -326,7 +330,9 @@ }

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);
var msg = this._errorMsg(key + " must be less than 2^256, given " + value);
throw new Error(msg);
}
}
else {
throw new Error('unimplemented bits value');
var msg = this._errorMsg('unimplemented bits value');
throw new Error(msg);
}

@@ -343,2 +349,32 @@ }

};
/**
* Returns the shared error postfix part for _error() method
* tx type implementations.
*/
BaseTransaction.prototype._getSharedErrorPostfix = function () {
var hash = '';
try {
hash = this.isSigned() ? (0, ethereumjs_util_1.bufferToHex)(this.hash()) : 'not available (unsigned)';
}
catch (e) {
hash = 'error';
}
var isSigned = '';
try {
isSigned = this.isSigned().toString();
}
catch (e) {
hash = 'error';
}
var hf = '';
try {
hf = this.common.hardfork();
}
catch (e) {
hf = 'error';
}
var postfix = "tx type=" + this.type + " hash=" + hash + " nonce=" + this.nonce + " value=" + this.value + " ";
postfix += "signed=" + isSigned + " hf=" + hf;
return postfix;
};
return BaseTransaction;

@@ -345,0 +381,0 @@ }());

@@ -156,2 +156,13 @@ /// <reference types="bn.js" />

toJSON(): JsonTx;
/**
* Return a compact error string representation of the object
*/
errorStr(): string;
/**
* Internal helper function to create an annotated error message
*
* @param msg Base error message
* @hidden
*/
protected _errorMsg(msg: string): string;
}

@@ -97,9 +97,12 @@ "use strict";

if (_this.maxFeePerGas.lt(_this.maxPriorityFeePerGas)) {
throw new Error('maxFeePerGas cannot be less than maxPriorityFeePerGas (The total must be the larger of the two)');
var msg = _this._errorMsg('maxFeePerGas cannot be less than maxPriorityFeePerGas (The total must be the larger of the two)');
throw new Error(msg);
}
if (_this.v && !_this.v.eqn(0) && !_this.v.eqn(1)) {
throw new Error('The y-parity of the transaction should either be 0 or 1');
var msg = _this._errorMsg('The y-parity of the transaction should either be 0 or 1');
throw new Error(msg);
}
if (_this.common.gteHardfork('homestead') && ((_a = _this.s) === null || _a === void 0 ? void 0 : _a.gt(types_1.N_DIV_2))) {
throw new Error('Invalid Signature: s-values greater than secp256k1n/2 are considered invalid');
var msg = _this._errorMsg('Invalid Signature: s-values greater than secp256k1n/2 are considered invalid');
throw new Error(msg);
}

@@ -225,4 +228,13 @@ var freeze = (_b = opts === null || opts === void 0 ? void 0 : opts.freeze) !== null && _b !== void 0 ? _b : true;

FeeMarketEIP1559Transaction.prototype.getDataFee = function () {
if (this.cache.dataFee && this.cache.dataFee.hardfork === this.common.hardfork()) {
return this.cache.dataFee.value;
}
var cost = _super.prototype.getDataFee.call(this);
cost.iaddn(util_1.AccessLists.getDataFeeEIP2930(this.accessList, this.common));
if (Object.isFrozen(this)) {
this.cache.dataFee = {
value: cost,
hardfork: this.common.hardfork(),
};
}
return cost;

@@ -315,3 +327,4 @@ };

if (!this.isSigned()) {
throw new Error('Cannot call hash method if transaction is not signed');
var msg = this._errorMsg('Cannot call hash method if transaction is not signed');
throw new Error(msg);
}

@@ -338,3 +351,4 @@ if (Object.isFrozen(this)) {

if (!this.isSigned()) {
throw new Error('Cannot call this method if transaction is not signed');
var msg = this._errorMsg('Cannot call this method if transaction is not signed');
throw new Error(msg);
}

@@ -345,3 +359,4 @@ var msgHash = this.getMessageToVerifySignature();

if (this.common.gteHardfork('homestead') && ((_a = this.s) === null || _a === void 0 ? void 0 : _a.gt(types_1.N_DIV_2))) {
throw new Error('Invalid Signature: s-values greater than secp256k1n/2 are considered invalid');
var msg = this._errorMsg('Invalid Signature: s-values greater than secp256k1n/2 are considered invalid');
throw new Error(msg);
}

@@ -354,3 +369,4 @@ var _b = this, v = _b.v, r = _b.r, s = _b.s;

catch (e) {
throw new Error('Invalid Signature');
var msg = this._errorMsg('Invalid Signature');
throw new Error(msg);
}

@@ -397,2 +413,19 @@ };

};
/**
* Return a compact error string representation of the object
*/
FeeMarketEIP1559Transaction.prototype.errorStr = function () {
var errorStr = this._getSharedErrorPostfix();
errorStr += " maxFeePerGas=" + this.maxFeePerGas + " maxPriorityFeePerGas=" + this.maxPriorityFeePerGas;
return errorStr;
};
/**
* Internal helper function to create an annotated error message
*
* @param msg Base error message
* @hidden
*/
FeeMarketEIP1559Transaction.prototype._errorMsg = function (msg) {
return msg + " (" + this.errorStr() + ")";
};
return FeeMarketEIP1559Transaction;

@@ -399,0 +432,0 @@ }(baseTransaction_1.BaseTransaction));

@@ -154,2 +154,13 @@ /// <reference types="bn.js" />

toJSON(): JsonTx;
/**
* Return a compact error string representation of the object
*/
errorStr(): string;
/**
* Internal helper function to create an annotated error message
*
* @param msg Base error message
* @hidden
*/
protected _errorMsg(msg: string): string;
}

@@ -94,6 +94,8 @@ "use strict";

if (_this.v && !_this.v.eqn(0) && !_this.v.eqn(1)) {
throw new Error('The y-parity of the transaction should either be 0 or 1');
var msg = _this._errorMsg('The y-parity of the transaction should either be 0 or 1');
throw new Error(msg);
}
if (_this.common.gteHardfork('homestead') && ((_a = _this.s) === null || _a === void 0 ? void 0 : _a.gt(types_1.N_DIV_2))) {
throw new Error('Invalid Signature: s-values greater than secp256k1n/2 are considered invalid');
var msg = _this._errorMsg('Invalid Signature: s-values greater than secp256k1n/2 are considered invalid');
throw new Error(msg);
}

@@ -219,4 +221,13 @@ var freeze = (_b = opts === null || opts === void 0 ? void 0 : opts.freeze) !== null && _b !== void 0 ? _b : true;

AccessListEIP2930Transaction.prototype.getDataFee = function () {
if (this.cache.dataFee && this.cache.dataFee.hardfork === this.common.hardfork()) {
return this.cache.dataFee.value;
}
var cost = _super.prototype.getDataFee.call(this);
cost.iaddn(util_1.AccessLists.getDataFeeEIP2930(this.accessList, this.common));
if (Object.isFrozen(this)) {
this.cache.dataFee = {
value: cost,
hardfork: this.common.hardfork(),
};
}
return cost;

@@ -304,3 +315,4 @@ };

if (!this.isSigned()) {
throw new Error('Cannot call hash method if transaction is not signed');
var msg = this._errorMsg('Cannot call hash method if transaction is not signed');
throw new Error(msg);
}

@@ -327,3 +339,4 @@ if (Object.isFrozen(this)) {

if (!this.isSigned()) {
throw new Error('Cannot call this method if transaction is not signed');
var msg = this._errorMsg('Cannot call this method if transaction is not signed');
throw new Error(msg);
}

@@ -334,3 +347,4 @@ var msgHash = this.getMessageToVerifySignature();

if (this.common.gteHardfork('homestead') && ((_a = this.s) === null || _a === void 0 ? void 0 : _a.gt(types_1.N_DIV_2))) {
throw new Error('Invalid Signature: s-values greater than secp256k1n/2 are considered invalid');
var msg = this._errorMsg('Invalid Signature: s-values greater than secp256k1n/2 are considered invalid');
throw new Error(msg);
}

@@ -343,3 +357,4 @@ var _b = this, yParity = _b.yParity, r = _b.r, s = _b.s;

catch (e) {
throw new Error('Invalid Signature');
var msg = this._errorMsg('Invalid Signature');
throw new Error(msg);
}

@@ -384,2 +399,21 @@ };

};
/**
* Return a compact error string representation of the object
*/
AccessListEIP2930Transaction.prototype.errorStr = function () {
var _a, _b;
var errorStr = this._getSharedErrorPostfix();
// Keep ? for this.accessList since this otherwise causes Hardhat E2E tests to fail
errorStr += " gasPrice=" + this.gasPrice + " accessListCount=" + ((_b = (_a = this.accessList) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0);
return errorStr;
};
/**
* Internal helper function to create an annotated error message
*
* @param msg Base error message
* @hidden
*/
AccessListEIP2930Transaction.prototype._errorMsg = function (msg) {
return msg + " (" + this.errorStr() + ")";
};
return AccessListEIP2930Transaction;

@@ -386,0 +420,0 @@ }(baseTransaction_1.BaseTransaction));

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

/**
* The amount of gas paid for the data in this tx
*/
getDataFee(): BN;
/**
* The up front amount that an account must have for this transaction to be valid

@@ -132,2 +136,13 @@ */

private _signedTxImplementsEIP155;
/**
* Return a compact error string representation of the object
*/
errorStr(): string;
/**
* Internal helper function to create an annotated error message
*
* @param msg Base error message
* @hidden
*/
protected _errorMsg(msg: string): string;
}

@@ -218,2 +218,17 @@ "use strict";

/**
* The amount of gas paid for the data in this tx
*/
Transaction.prototype.getDataFee = function () {
if (this.cache.dataFee && this.cache.dataFee.hardfork === this.common.hardfork()) {
return this.cache.dataFee.value;
}
if (Object.isFrozen(this)) {
this.cache.dataFee = {
value: _super.prototype.getDataFee.call(this),
hardfork: this.common.hardfork(),
};
}
return _super.prototype.getDataFee.call(this);
};
/**
* The up front amount that an account must have for this transaction to be valid

@@ -242,3 +257,4 @@ */

//if (!this.isSigned()) {
// throw new Error('Cannot call hash method if transaction is not signed')
// const msg = this._errorMsg('Cannot call hash method if transaction is not signed')
// throw new Error(msg)
//}

@@ -258,3 +274,4 @@ if (Object.isFrozen(this)) {

if (!this.isSigned()) {
throw Error('This transaction is not signed');
var msg = this._errorMsg('This transaction is not signed');
throw new Error(msg);
}

@@ -273,3 +290,4 @@ var message = this._getMessageToSign();

if (this.common.gteHardfork('homestead') && ((_a = this.s) === null || _a === void 0 ? void 0 : _a.gt(types_1.N_DIV_2))) {
throw new Error('Invalid Signature: s-values greater than secp256k1n/2 are considered invalid');
var msg = this._errorMsg('Invalid Signature: s-values greater than secp256k1n/2 are considered invalid');
throw new Error(msg);
}

@@ -281,3 +299,4 @@ var _b = this, v = _b.v, r = _b.r, s = _b.s;

catch (e) {
throw new Error('Invalid Signature');
var msg = this._errorMsg('Invalid Signature');
throw new Error(msg);
}

@@ -339,5 +358,3 @@ };

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.");
throw new Error("Incompatible EIP155-based V " + v + " and chain id " + common.chainIdBN() + ". See the Common parameter of the Transaction constructor to set the chain id.");
}

@@ -371,3 +388,4 @@ }

if (!this.isSigned()) {
throw Error('This transaction is not signed');
var msg = this._errorMsg('This transaction is not signed');
throw new Error(msg);
}

@@ -382,2 +400,19 @@ var onEIP155BlockOrLater = this.common.gteHardfork('spuriousDragon');

};
/**
* Return a compact error string representation of the object
*/
Transaction.prototype.errorStr = function () {
var errorStr = this._getSharedErrorPostfix();
errorStr += " gasPrice=" + this.gasPrice;
return errorStr;
};
/**
* Internal helper function to create an annotated error message
*
* @param msg Base error message
* @hidden
*/
Transaction.prototype._errorMsg = function (msg) {
return msg + " (" + this.errorStr() + ")";
};
return Transaction;

@@ -384,0 +419,0 @@ }(baseTransaction_1.BaseTransaction));

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

hash: Buffer | undefined;
dataFee?: {
value: BN;
hardfork: string | Hardfork;
};
}

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

}, bits?: number): void;
/**
* Return a compact error string representation of the object
*/
abstract errorStr(): string;
/**
* Internal helper function to create an annotated error message
*
* @param msg Base error message
* @hidden
*/
protected abstract _errorMsg(msg: string): string;
/**
* Returns the shared error postfix part for _error() method
* tx type implementations.
*/
protected _getSharedErrorPostfix(): string;
}
export {};

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

hash: undefined,
dataFee: undefined,
};

@@ -205,3 +206,4 @@ /**

if (privateKey.length !== 32) {
throw new Error('Private key must be 32 bytes in length.');
const msg = this._errorMsg('Private key must be 32 bytes in length.');
throw new Error(msg);
}

@@ -246,3 +248,4 @@ // Hack for the constellation that we have got a legacy tx after spuriousDragon with a non-EIP155 conforming signature

if (!common.chainIdBN().eq(chainIdBN)) {
throw new Error('The chain ID does not match the chain ID of Common');
const msg = this._errorMsg('The chain ID does not match the chain ID of Common');
throw new Error(msg);
}

@@ -280,3 +283,4 @@ // Common provided, chain ID does match

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}`);
const msg = this._errorMsg(`${key} cannot exceed MAX_INTEGER, given ${value}`);
throw new Error(msg);
}

@@ -286,12 +290,44 @@ }

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}`);
const msg = this._errorMsg(`${key} must be less than 2^256, given ${value}`);
throw new Error(msg);
}
}
else {
throw new Error('unimplemented bits value');
const msg = this._errorMsg('unimplemented bits value');
throw new Error(msg);
}
}
}
/**
* Returns the shared error postfix part for _error() method
* tx type implementations.
*/
_getSharedErrorPostfix() {
let hash = '';
try {
hash = this.isSigned() ? (0, ethereumjs_util_1.bufferToHex)(this.hash()) : 'not available (unsigned)';
}
catch (e) {
hash = 'error';
}
let isSigned = '';
try {
isSigned = this.isSigned().toString();
}
catch (e) {
hash = 'error';
}
let hf = '';
try {
hf = this.common.hardfork();
}
catch (e) {
hf = 'error';
}
let postfix = `tx type=${this.type} hash=${hash} nonce=${this.nonce} value=${this.value} `;
postfix += `signed=${isSigned} hf=${hf}`;
return postfix;
}
}
exports.BaseTransaction = BaseTransaction;
//# sourceMappingURL=baseTransaction.js.map

@@ -156,2 +156,13 @@ /// <reference types="bn.js" />

toJSON(): JsonTx;
/**
* Return a compact error string representation of the object
*/
errorStr(): string;
/**
* Internal helper function to create an annotated error message
*
* @param msg Base error message
* @hidden
*/
protected _errorMsg(msg: string): string;
}

@@ -53,9 +53,12 @@ "use strict";

if (this.maxFeePerGas.lt(this.maxPriorityFeePerGas)) {
throw new Error('maxFeePerGas cannot be less than maxPriorityFeePerGas (The total must be the larger of the two)');
const msg = this._errorMsg('maxFeePerGas cannot be less than maxPriorityFeePerGas (The total must be the larger of the two)');
throw new Error(msg);
}
if (this.v && !this.v.eqn(0) && !this.v.eqn(1)) {
throw new Error('The y-parity of the transaction should either be 0 or 1');
const msg = this._errorMsg('The y-parity of the transaction should either be 0 or 1');
throw new Error(msg);
}
if (this.common.gteHardfork('homestead') && ((_a = this.s) === null || _a === void 0 ? void 0 : _a.gt(types_1.N_DIV_2))) {
throw new Error('Invalid Signature: s-values greater than secp256k1n/2 are considered invalid');
const msg = this._errorMsg('Invalid Signature: s-values greater than secp256k1n/2 are considered invalid');
throw new Error(msg);
}

@@ -164,4 +167,13 @@ const freeze = (_b = opts === null || opts === void 0 ? void 0 : opts.freeze) !== null && _b !== void 0 ? _b : true;

getDataFee() {
if (this.cache.dataFee && this.cache.dataFee.hardfork === this.common.hardfork()) {
return this.cache.dataFee.value;
}
const cost = super.getDataFee();
cost.iaddn(util_1.AccessLists.getDataFeeEIP2930(this.accessList, this.common));
if (Object.isFrozen(this)) {
this.cache.dataFee = {
value: cost,
hardfork: this.common.hardfork(),
};
}
return cost;

@@ -252,3 +264,4 @@ }

if (!this.isSigned()) {
throw new Error('Cannot call hash method if transaction is not signed');
const msg = this._errorMsg('Cannot call hash method if transaction is not signed');
throw new Error(msg);
}

@@ -275,3 +288,4 @@ if (Object.isFrozen(this)) {

if (!this.isSigned()) {
throw new Error('Cannot call this method if transaction is not signed');
const msg = this._errorMsg('Cannot call this method if transaction is not signed');
throw new Error(msg);
}

@@ -282,3 +296,4 @@ const msgHash = this.getMessageToVerifySignature();

if (this.common.gteHardfork('homestead') && ((_a = this.s) === null || _a === void 0 ? void 0 : _a.gt(types_1.N_DIV_2))) {
throw new Error('Invalid Signature: s-values greater than secp256k1n/2 are considered invalid');
const msg = this._errorMsg('Invalid Signature: s-values greater than secp256k1n/2 are considered invalid');
throw new Error(msg);
}

@@ -291,3 +306,4 @@ const { v, r, s } = this;

catch (e) {
throw new Error('Invalid Signature');
const msg = this._errorMsg('Invalid Signature');
throw new Error(msg);
}

@@ -334,4 +350,21 @@ }

}
/**
* Return a compact error string representation of the object
*/
errorStr() {
let errorStr = this._getSharedErrorPostfix();
errorStr += ` maxFeePerGas=${this.maxFeePerGas} maxPriorityFeePerGas=${this.maxPriorityFeePerGas}`;
return errorStr;
}
/**
* Internal helper function to create an annotated error message
*
* @param msg Base error message
* @hidden
*/
_errorMsg(msg) {
return `${msg} (${this.errorStr()})`;
}
}
exports.default = FeeMarketEIP1559Transaction;
//# sourceMappingURL=eip1559Transaction.js.map

@@ -154,2 +154,13 @@ /// <reference types="bn.js" />

toJSON(): JsonTx;
/**
* Return a compact error string representation of the object
*/
errorStr(): string;
/**
* Internal helper function to create an annotated error message
*
* @param msg Base error message
* @hidden
*/
protected _errorMsg(msg: string): string;
}

@@ -50,6 +50,8 @@ "use strict";

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

@@ -158,4 +160,13 @@ const freeze = (_b = opts === null || opts === void 0 ? void 0 : opts.freeze) !== null && _b !== void 0 ? _b : true;

getDataFee() {
if (this.cache.dataFee && this.cache.dataFee.hardfork === this.common.hardfork()) {
return this.cache.dataFee.value;
}
const cost = super.getDataFee();
cost.iaddn(util_1.AccessLists.getDataFeeEIP2930(this.accessList, this.common));
if (Object.isFrozen(this)) {
this.cache.dataFee = {
value: cost,
hardfork: this.common.hardfork(),
};
}
return cost;

@@ -242,3 +253,4 @@ }

if (!this.isSigned()) {
throw new Error('Cannot call hash method if transaction is not signed');
const msg = this._errorMsg('Cannot call hash method if transaction is not signed');
throw new Error(msg);
}

@@ -265,3 +277,4 @@ if (Object.isFrozen(this)) {

if (!this.isSigned()) {
throw new Error('Cannot call this method if transaction is not signed');
const msg = this._errorMsg('Cannot call this method if transaction is not signed');
throw new Error(msg);
}

@@ -272,3 +285,4 @@ const msgHash = this.getMessageToVerifySignature();

if (this.common.gteHardfork('homestead') && ((_a = this.s) === null || _a === void 0 ? void 0 : _a.gt(types_1.N_DIV_2))) {
throw new Error('Invalid Signature: s-values greater than secp256k1n/2 are considered invalid');
const msg = this._errorMsg('Invalid Signature: s-values greater than secp256k1n/2 are considered invalid');
throw new Error(msg);
}

@@ -281,3 +295,4 @@ const { yParity, r, s } = this;

catch (e) {
throw new Error('Invalid Signature');
const msg = this._errorMsg('Invalid Signature');
throw new Error(msg);
}

@@ -322,4 +337,23 @@ }

}
/**
* Return a compact error string representation of the object
*/
errorStr() {
var _a, _b;
let errorStr = this._getSharedErrorPostfix();
// Keep ? for this.accessList since this otherwise causes Hardhat E2E tests to fail
errorStr += ` gasPrice=${this.gasPrice} accessListCount=${(_b = (_a = this.accessList) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0}`;
return errorStr;
}
/**
* Internal helper function to create an annotated error message
*
* @param msg Base error message
* @hidden
*/
_errorMsg(msg) {
return `${msg} (${this.errorStr()})`;
}
}
exports.default = AccessListEIP2930Transaction;
//# sourceMappingURL=eip2930Transaction.js.map

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

/**
* The amount of gas paid for the data in this tx
*/
getDataFee(): BN;
/**
* The up front amount that an account must have for this transaction to be valid

@@ -132,2 +136,13 @@ */

private _signedTxImplementsEIP155;
/**
* Return a compact error string representation of the object
*/
errorStr(): string;
/**
* Internal helper function to create an annotated error message
*
* @param msg Base error message
* @hidden
*/
protected _errorMsg(msg: string): string;
}

@@ -168,2 +168,17 @@ "use strict";

/**
* The amount of gas paid for the data in this tx
*/
getDataFee() {
if (this.cache.dataFee && this.cache.dataFee.hardfork === this.common.hardfork()) {
return this.cache.dataFee.value;
}
if (Object.isFrozen(this)) {
this.cache.dataFee = {
value: super.getDataFee(),
hardfork: this.common.hardfork(),
};
}
return super.getDataFee();
}
/**
* The up front amount that an account must have for this transaction to be valid

@@ -192,3 +207,4 @@ */

//if (!this.isSigned()) {
// throw new Error('Cannot call hash method if transaction is not signed')
// const msg = this._errorMsg('Cannot call hash method if transaction is not signed')
// throw new Error(msg)
//}

@@ -208,3 +224,4 @@ if (Object.isFrozen(this)) {

if (!this.isSigned()) {
throw Error('This transaction is not signed');
const msg = this._errorMsg('This transaction is not signed');
throw new Error(msg);
}

@@ -223,3 +240,4 @@ const message = this._getMessageToSign();

if (this.common.gteHardfork('homestead') && ((_a = this.s) === null || _a === void 0 ? void 0 : _a.gt(types_1.N_DIV_2))) {
throw new Error('Invalid Signature: s-values greater than secp256k1n/2 are considered invalid');
const msg = this._errorMsg('Invalid Signature: s-values greater than secp256k1n/2 are considered invalid');
throw new Error(msg);
}

@@ -231,3 +249,4 @@ const { v, r, s } = this;

catch (e) {
throw new Error('Invalid Signature');
const msg = this._errorMsg('Invalid Signature');
throw new Error(msg);
}

@@ -289,5 +308,3 @@ }

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.`);
throw new Error(`Incompatible EIP155-based V ${v} and chain id ${common.chainIdBN()}. See the Common parameter of the Transaction constructor to set the chain id.`);
}

@@ -321,3 +338,4 @@ }

if (!this.isSigned()) {
throw Error('This transaction is not signed');
const msg = this._errorMsg('This transaction is not signed');
throw new Error(msg);
}

@@ -332,4 +350,21 @@ const onEIP155BlockOrLater = this.common.gteHardfork('spuriousDragon');

}
/**
* Return a compact error string representation of the object
*/
errorStr() {
let errorStr = this._getSharedErrorPostfix();
errorStr += ` gasPrice=${this.gasPrice}`;
return errorStr;
}
/**
* Internal helper function to create an annotated error message
*
* @param msg Base error message
* @hidden
*/
_errorMsg(msg) {
return `${msg} (${this.errorStr()})`;
}
}
exports.default = Transaction;
//# sourceMappingURL=legacyTransaction.js.map

9

package.json
{
"name": "@ethereumjs/tx",
"version": "3.3.2",
"version": "3.4.0",
"description": "A simple module for creating, manipulating and signing Ethereum transactions",

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

"lint:fix": "../../config/cli/lint-fix.sh",
"tape": "tape -r ts-node/register",
"test": "npm run test:node && npm run test:browser",

@@ -38,4 +39,4 @@ "test:node": "tape -r ts-node/register ./test/index.ts",

"dependencies": {
"@ethereumjs/common": "^2.5.0",
"ethereumjs-util": "^7.1.2"
"@ethereumjs/common": "^2.6.0",
"ethereumjs-util": "^7.1.3"
},

@@ -54,3 +55,3 @@ "devDependencies": {

"node-dir": "^0.1.16",
"nyc": "^14.0.0",
"nyc": "^15.1.0",
"prettier": "^2.0.5",

@@ -57,0 +58,0 @@ "tape": "^5.3.1",

@@ -236,5 +236,8 @@ # @ethereumjs/tx

| xDai Chain | `Common.xDaiChain` | [#1323](https://github.com/ethereumjs/ethereumjs-monorepo/issues/1323) |
| Optimistic Kovan | `Common.OptimisticKovan` | [#1554](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1554)
| Optimistic Ethereum | `Common.OptimisticEthereum` | [#1554](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1554)
Note: For Optimistic Kovan and Optimistic Ethereum, the London hardfork has not been implemented so transactions submitted with a `baseFee` will revert.
The London hardfork is targeted to implement on Optimism in Q1.22.
For a non-predefined custom chain it is also possible to just provide a chain ID as well as other parameters to `Common`:

@@ -241,0 +244,0 @@

@@ -12,2 +12,3 @@ import Common, { Chain, Hardfork } from '@ethereumjs/common'

BNLike,
bufferToHex,
} from 'ethereumjs-util'

@@ -27,2 +28,6 @@ import {

hash: Buffer | undefined
dataFee?: {
value: BN
hardfork: string | Hardfork
}
}

@@ -54,2 +59,3 @@

hash: undefined,
dataFee: undefined,
}

@@ -191,2 +197,3 @@

}
return new BN(cost)

@@ -288,3 +295,4 @@ }

if (privateKey.length !== 32) {
throw new Error('Private key must be 32 bytes in length.')
const msg = this._errorMsg('Private key must be 32 bytes in length.')
throw new Error(msg)
}

@@ -343,3 +351,4 @@

if (!common.chainIdBN().eq(chainIdBN)) {
throw new Error('The chain ID does not match the chain ID of Common')
const msg = this._errorMsg('The chain ID does not match the chain ID of Common')
throw new Error(msg)
}

@@ -381,13 +390,59 @@ // Common provided, chain ID does match

if (value?.gt(MAX_INTEGER)) {
throw new Error(`${key} cannot exceed MAX_INTEGER, given ${value}`)
const msg = this._errorMsg(`${key} cannot exceed MAX_INTEGER, given ${value}`)
throw new Error(msg)
}
} else if (bits === 256) {
if (value?.gte(TWO_POW256)) {
throw new Error(`${key} must be less than 2^256, given ${value}`)
const msg = this._errorMsg(`${key} must be less than 2^256, given ${value}`)
throw new Error(msg)
}
} else {
throw new Error('unimplemented bits value')
const msg = this._errorMsg('unimplemented bits value')
throw new Error(msg)
}
}
}
/**
* Return a compact error string representation of the object
*/
public abstract errorStr(): string
/**
* Internal helper function to create an annotated error message
*
* @param msg Base error message
* @hidden
*/
protected abstract _errorMsg(msg: string): string
/**
* Returns the shared error postfix part for _error() method
* tx type implementations.
*/
protected _getSharedErrorPostfix() {
let hash = ''
try {
hash = this.isSigned() ? bufferToHex(this.hash()) : 'not available (unsigned)'
} catch (e: any) {
hash = 'error'
}
let isSigned = ''
try {
isSigned = this.isSigned().toString()
} catch (e: any) {
hash = 'error'
}
let hf = ''
try {
hf = this.common.hardfork()
} catch (e: any) {
hf = 'error'
}
let postfix = `tx type=${this.type} hash=${hash} nonce=${this.nonce} value=${this.value} `
postfix += `signed=${isSigned} hf=${hf}`
return postfix
}
}

@@ -214,15 +214,18 @@ import {

if (this.maxFeePerGas.lt(this.maxPriorityFeePerGas)) {
throw new Error(
const msg = this._errorMsg(
'maxFeePerGas cannot be less than maxPriorityFeePerGas (The total must be the larger of the two)'
)
throw new Error(msg)
}
if (this.v && !this.v.eqn(0) && !this.v.eqn(1)) {
throw new Error('The y-parity of the transaction should either be 0 or 1')
const msg = this._errorMsg('The y-parity of the transaction should either be 0 or 1')
throw new Error(msg)
}
if (this.common.gteHardfork('homestead') && this.s?.gt(N_DIV_2)) {
throw new Error(
const msg = this._errorMsg(
'Invalid Signature: s-values greater than secp256k1n/2 are considered invalid'
)
throw new Error(msg)
}

@@ -240,4 +243,16 @@

getDataFee(): BN {
if (this.cache.dataFee && this.cache.dataFee.hardfork === this.common.hardfork()) {
return this.cache.dataFee.value
}
const cost = super.getDataFee()
cost.iaddn(AccessLists.getDataFeeEIP2930(this.accessList, this.common))
if (Object.isFrozen(this)) {
this.cache.dataFee = {
value: cost,
hardfork: this.common.hardfork(),
}
}
return cost

@@ -332,3 +347,4 @@ }

if (!this.isSigned()) {
throw new Error('Cannot call hash method if transaction is not signed')
const msg = this._errorMsg('Cannot call hash method if transaction is not signed')
throw new Error(msg)
}

@@ -358,3 +374,4 @@

if (!this.isSigned()) {
throw new Error('Cannot call this method if transaction is not signed')
const msg = this._errorMsg('Cannot call this method if transaction is not signed')
throw new Error(msg)
}

@@ -367,5 +384,6 @@

if (this.common.gteHardfork('homestead') && this.s?.gt(N_DIV_2)) {
throw new Error(
const msg = this._errorMsg(
'Invalid Signature: s-values greater than secp256k1n/2 are considered invalid'
)
throw new Error(msg)
}

@@ -382,3 +400,4 @@

} catch (e: any) {
throw new Error('Invalid Signature')
const msg = this._errorMsg('Invalid Signature')
throw new Error(msg)
}

@@ -432,2 +451,21 @@ }

}
/**
* Return a compact error string representation of the object
*/
public errorStr() {
let errorStr = this._getSharedErrorPostfix()
errorStr += ` maxFeePerGas=${this.maxFeePerGas} maxPriorityFeePerGas=${this.maxPriorityFeePerGas}`
return errorStr
}
/**
* Internal helper function to create an annotated error message
*
* @param msg Base error message
* @hidden
*/
protected _errorMsg(msg: string) {
return `${msg} (${this.errorStr()})`
}
}

@@ -194,9 +194,11 @@ import {

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

@@ -214,4 +216,16 @@

getDataFee(): BN {
if (this.cache.dataFee && this.cache.dataFee.hardfork === this.common.hardfork()) {
return this.cache.dataFee.value
}
const cost = super.getDataFee()
cost.iaddn(AccessLists.getDataFeeEIP2930(this.accessList, this.common))
if (Object.isFrozen(this)) {
this.cache.dataFee = {
value: cost,
hardfork: this.common.hardfork(),
}
}
return cost

@@ -302,3 +316,4 @@ }

if (!this.isSigned()) {
throw new Error('Cannot call hash method if transaction is not signed')
const msg = this._errorMsg('Cannot call hash method if transaction is not signed')
throw new Error(msg)
}

@@ -328,3 +343,4 @@

if (!this.isSigned()) {
throw new Error('Cannot call this method if transaction is not signed')
const msg = this._errorMsg('Cannot call this method if transaction is not signed')
throw new Error(msg)
}

@@ -337,5 +353,6 @@

if (this.common.gteHardfork('homestead') && this.s?.gt(N_DIV_2)) {
throw new Error(
const msg = this._errorMsg(
'Invalid Signature: s-values greater than secp256k1n/2 are considered invalid'
)
throw new Error(msg)
}

@@ -352,3 +369,4 @@

} catch (e: any) {
throw new Error('Invalid Signature')
const msg = this._errorMsg('Invalid Signature')
throw new Error(msg)
}

@@ -400,2 +418,22 @@ }

}
/**
* Return a compact error string representation of the object
*/
public errorStr() {
let errorStr = this._getSharedErrorPostfix()
// Keep ? for this.accessList since this otherwise causes Hardhat E2E tests to fail
errorStr += ` gasPrice=${this.gasPrice} accessListCount=${this.accessList?.length ?? 0}`
return errorStr
}
/**
* Internal helper function to create an annotated error message
*
* @param msg Base error message
* @hidden
*/
protected _errorMsg(msg: string) {
return `${msg} (${this.errorStr()})`
}
}

@@ -222,2 +222,20 @@ import {

/**
* The amount of gas paid for the data in this tx
*/
getDataFee(): BN {
if (this.cache.dataFee && this.cache.dataFee.hardfork === this.common.hardfork()) {
return this.cache.dataFee.value
}
if (Object.isFrozen(this)) {
this.cache.dataFee = {
value: super.getDataFee(),
hardfork: this.common.hardfork(),
}
}
return super.getDataFee()
}
/**
* The up front amount that an account must have for this transaction to be valid

@@ -247,3 +265,4 @@ */

//if (!this.isSigned()) {
// throw new Error('Cannot call hash method if transaction is not signed')
// const msg = this._errorMsg('Cannot call hash method if transaction is not signed')
// throw new Error(msg)
//}

@@ -266,3 +285,4 @@

if (!this.isSigned()) {
throw Error('This transaction is not signed')
const msg = this._errorMsg('This transaction is not signed')
throw new Error(msg)
}

@@ -282,5 +302,6 @@ const message = this._getMessageToSign()

if (this.common.gteHardfork('homestead') && this.s?.gt(N_DIV_2)) {
throw new Error(
const msg = this._errorMsg(
'Invalid Signature: s-values greater than secp256k1n/2 are considered invalid'
)
throw new Error(msg)
}

@@ -298,3 +319,4 @@

} catch (e: any) {
throw new Error('Invalid Signature')
const msg = this._errorMsg('Invalid Signature')
throw new Error(msg)
}

@@ -368,5 +390,3 @@ }

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.`
`Incompatible EIP155-based V ${v} and chain id ${common.chainIdBN()}. See the Common parameter of the Transaction constructor to set the chain id.`
)

@@ -401,3 +421,4 @@ }

if (!this.isSigned()) {
throw Error('This transaction is not signed')
const msg = this._errorMsg('This transaction is not signed')
throw new Error(msg)
}

@@ -417,2 +438,21 @@ const onEIP155BlockOrLater = this.common.gteHardfork('spuriousDragon')

}
/**
* Return a compact error string representation of the object
*/
public errorStr() {
let errorStr = this._getSharedErrorPostfix()
errorStr += ` gasPrice=${this.gasPrice}`
return errorStr
}
/**
* Internal helper function to create an annotated error message
*
* @param msg Base error message
* @hidden
*/
protected _errorMsg(msg: string) {
return `${msg} (${this.errorStr()})`
}
}

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