Socket
Socket
Sign inDemoInstall

@ethersproject/transactions

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ethersproject/transactions - npm Package Compare versions

Comparing version 5.3.0 to 5.4.0

2

lib.esm/_version.d.ts

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

export declare const version = "transactions/5.3.0";
export declare const version = "transactions/5.4.0";
//# sourceMappingURL=_version.d.ts.map

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

export const version = "transactions/5.3.0";
export const version = "transactions/5.4.0";
//# sourceMappingURL=_version.js.map

@@ -8,2 +8,7 @@ import { BigNumber, BigNumberish } from "@ethersproject/bignumber";

export declare type AccessListish = AccessList | Array<[string, Array<string>]> | Record<string, Array<string>>;
export declare enum TransactionTypes {
legacy = 0,
eip2930 = 1,
eip1559 = 2
}
export declare type UnsignedTransaction = {

@@ -19,2 +24,4 @@ to?: string;

accessList?: AccessListish;
maxPriorityFeePerGas?: BigNumberish;
maxFeePerGas?: BigNumberish;
};

@@ -27,3 +34,3 @@ export interface Transaction {

gasLimit: BigNumber;
gasPrice: BigNumber;
gasPrice?: BigNumber;
data: string;

@@ -37,2 +44,4 @@ value: BigNumber;

accessList?: AccessList;
maxPriorityFeePerGas?: BigNumber;
maxFeePerGas?: BigNumber;
}

@@ -39,0 +48,0 @@ export declare function computeAddress(key: BytesLike | string): string;

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

const logger = new Logger(version);
export var TransactionTypes;
(function (TransactionTypes) {
TransactionTypes[TransactionTypes["legacy"] = 0] = "legacy";
TransactionTypes[TransactionTypes["eip2930"] = 1] = "eip2930";
TransactionTypes[TransactionTypes["eip1559"] = 2] = "eip1559";
})(TransactionTypes || (TransactionTypes = {}));
;
///////////////////////////////

@@ -37,3 +44,3 @@ function handleAddress(value) {

const allowedTransactionKeys = {
chainId: true, data: true, gasLimit: true, gasPrice: true, nonce: true, to: true, value: true
chainId: true, data: true, gasLimit: true, gasPrice: true, nonce: true, to: true, type: true, value: true
};

@@ -90,2 +97,34 @@ export function computeAddress(key) {

}
function _serializeEip1559(transaction, signature) {
// If there is an explicit gasPrice, make sure it matches the
// EIP-1559 fees; otherwise they may not understand what they
// think they are setting in terms of fee.
if (transaction.gasPrice != null) {
const gasPrice = BigNumber.from(transaction.gasPrice);
const maxFeePerGas = BigNumber.from(transaction.maxFeePerGas || 0);
if (!gasPrice.eq(maxFeePerGas)) {
logger.throwArgumentError("mismatch EIP-1559 gasPrice != maxFeePerGas", "tx", {
gasPrice, maxFeePerGas
});
}
}
const fields = [
formatNumber(transaction.chainId || 0, "chainId"),
formatNumber(transaction.nonce || 0, "nonce"),
formatNumber(transaction.maxPriorityFeePerGas || 0, "maxPriorityFeePerGas"),
formatNumber(transaction.maxFeePerGas || 0, "maxFeePerGas"),
formatNumber(transaction.gasLimit || 0, "gasLimit"),
((transaction.to != null) ? getAddress(transaction.to) : "0x"),
formatNumber(transaction.value || 0, "value"),
(transaction.data || "0x"),
(formatAccessList(transaction.accessList || []))
];
if (signature) {
const sig = splitSignature(signature);
fields.push(formatNumber(sig.recoveryParam, "recoveryParam"));
fields.push(stripZeros(sig.r));
fields.push(stripZeros(sig.s));
}
return hexConcat(["0x02", RLP.encode(fields)]);
}
function _serializeEip2930(transaction, signature) {

@@ -181,3 +220,3 @@ const fields = [

// Legacy and EIP-155 Transactions
if (transaction.type == null) {
if (transaction.type == null || transaction.type === 0) {
if (transaction.accessList != null) {

@@ -192,2 +231,4 @@ logger.throwArgumentError("untyped transactions do not support accessList; include type: 1", "transaction", transaction);

return _serializeEip2930(transaction, signature);
case 2:
return _serializeEip1559(transaction, signature);
default:

@@ -201,2 +242,51 @@ break;

}
function _parseEipSignature(tx, fields, serialize) {
try {
const recid = handleNumber(fields[0]).toNumber();
if (recid !== 0 && recid !== 1) {
throw new Error("bad recid");
}
tx.v = recid;
}
catch (error) {
logger.throwArgumentError("invalid v for transaction type: 1", "v", fields[0]);
}
tx.r = hexZeroPad(fields[1], 32);
tx.s = hexZeroPad(fields[2], 32);
try {
const digest = keccak256(serialize(tx));
tx.from = recoverAddress(digest, { r: tx.r, s: tx.s, recoveryParam: tx.v });
}
catch (error) {
console.log(error);
}
}
function _parseEip1559(payload) {
const transaction = RLP.decode(payload.slice(1));
if (transaction.length !== 9 && transaction.length !== 12) {
logger.throwArgumentError("invalid component count for transaction type: 2", "payload", hexlify(payload));
}
const maxPriorityFeePerGas = handleNumber(transaction[2]);
const maxFeePerGas = handleNumber(transaction[3]);
const tx = {
type: 2,
chainId: handleNumber(transaction[0]).toNumber(),
nonce: handleNumber(transaction[1]).toNumber(),
maxPriorityFeePerGas: maxPriorityFeePerGas,
maxFeePerGas: maxFeePerGas,
gasPrice: null,
gasLimit: handleNumber(transaction[4]),
to: handleAddress(transaction[5]),
value: handleNumber(transaction[6]),
data: transaction[7],
accessList: accessListify(transaction[8]),
};
// Unsigned EIP-1559 Transaction
if (transaction.length === 9) {
return tx;
}
tx.hash = keccak256(payload);
_parseEipSignature(tx, transaction.slice(9), _serializeEip1559);
return tx;
}
function _parseEip2930(payload) {

@@ -216,3 +306,3 @@ const transaction = RLP.decode(payload.slice(1));

data: transaction[6],
accessList: accessListify(transaction[7]),
accessList: accessListify(transaction[7])
};

@@ -223,22 +313,4 @@ // Unsigned EIP-2930 Transaction

}
try {
const recid = handleNumber(transaction[8]).toNumber();
if (recid !== 0 && recid !== 1) {
throw new Error("bad recid");
}
tx.v = recid;
}
catch (error) {
logger.throwArgumentError("invalid v for transaction type: 1", "v", transaction[8]);
}
tx.r = hexZeroPad(transaction[9], 32);
tx.s = hexZeroPad(transaction[10], 32);
try {
const digest = keccak256(_serializeEip2930(tx));
tx.from = recoverAddress(digest, { r: tx.r, s: tx.s, recoveryParam: tx.v });
}
catch (error) {
console.log(error);
}
tx.hash = keccak256(payload);
_parseEipSignature(tx, transaction.slice(8), _serializeEip2930);
return tx;

@@ -315,2 +387,4 @@ }

return _parseEip2930(payload);
case 2:
return _parseEip1559(payload);
default:

@@ -317,0 +391,0 @@ break;

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

export declare const version = "transactions/5.3.0";
export declare const version = "transactions/5.4.0";
//# sourceMappingURL=_version.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.version = void 0;
exports.version = "transactions/5.3.0";
exports.version = "transactions/5.4.0";
//# sourceMappingURL=_version.js.map

@@ -8,2 +8,7 @@ import { BigNumber, BigNumberish } from "@ethersproject/bignumber";

export declare type AccessListish = AccessList | Array<[string, Array<string>]> | Record<string, Array<string>>;
export declare enum TransactionTypes {
legacy = 0,
eip2930 = 1,
eip1559 = 2
}
export declare type UnsignedTransaction = {

@@ -19,2 +24,4 @@ to?: string;

accessList?: AccessListish;
maxPriorityFeePerGas?: BigNumberish;
maxFeePerGas?: BigNumberish;
};

@@ -27,3 +34,3 @@ export interface Transaction {

gasLimit: BigNumber;
gasPrice: BigNumber;
gasPrice?: BigNumber;
data: string;

@@ -37,2 +44,4 @@ value: BigNumber;

accessList?: AccessList;
maxPriorityFeePerGas?: BigNumber;
maxFeePerGas?: BigNumber;
}

@@ -39,0 +48,0 @@ export declare function computeAddress(key: BytesLike | string): string;

@@ -22,3 +22,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.parse = exports.serialize = exports.accessListify = exports.recoverAddress = exports.computeAddress = void 0;
exports.parse = exports.serialize = exports.accessListify = exports.recoverAddress = exports.computeAddress = exports.TransactionTypes = void 0;
var address_1 = require("@ethersproject/address");

@@ -35,2 +35,9 @@ var bignumber_1 = require("@ethersproject/bignumber");

var logger = new logger_1.Logger(_version_1.version);
var TransactionTypes;
(function (TransactionTypes) {
TransactionTypes[TransactionTypes["legacy"] = 0] = "legacy";
TransactionTypes[TransactionTypes["eip2930"] = 1] = "eip2930";
TransactionTypes[TransactionTypes["eip1559"] = 2] = "eip1559";
})(TransactionTypes = exports.TransactionTypes || (exports.TransactionTypes = {}));
;
///////////////////////////////

@@ -59,3 +66,3 @@ function handleAddress(value) {

var allowedTransactionKeys = {
chainId: true, data: true, gasLimit: true, gasPrice: true, nonce: true, to: true, value: true
chainId: true, data: true, gasLimit: true, gasPrice: true, nonce: true, to: true, type: true, value: true
};

@@ -115,2 +122,34 @@ function computeAddress(key) {

}
function _serializeEip1559(transaction, signature) {
// If there is an explicit gasPrice, make sure it matches the
// EIP-1559 fees; otherwise they may not understand what they
// think they are setting in terms of fee.
if (transaction.gasPrice != null) {
var gasPrice = bignumber_1.BigNumber.from(transaction.gasPrice);
var maxFeePerGas = bignumber_1.BigNumber.from(transaction.maxFeePerGas || 0);
if (!gasPrice.eq(maxFeePerGas)) {
logger.throwArgumentError("mismatch EIP-1559 gasPrice != maxFeePerGas", "tx", {
gasPrice: gasPrice, maxFeePerGas: maxFeePerGas
});
}
}
var fields = [
formatNumber(transaction.chainId || 0, "chainId"),
formatNumber(transaction.nonce || 0, "nonce"),
formatNumber(transaction.maxPriorityFeePerGas || 0, "maxPriorityFeePerGas"),
formatNumber(transaction.maxFeePerGas || 0, "maxFeePerGas"),
formatNumber(transaction.gasLimit || 0, "gasLimit"),
((transaction.to != null) ? address_1.getAddress(transaction.to) : "0x"),
formatNumber(transaction.value || 0, "value"),
(transaction.data || "0x"),
(formatAccessList(transaction.accessList || []))
];
if (signature) {
var sig = bytes_1.splitSignature(signature);
fields.push(formatNumber(sig.recoveryParam, "recoveryParam"));
fields.push(bytes_1.stripZeros(sig.r));
fields.push(bytes_1.stripZeros(sig.s));
}
return bytes_1.hexConcat(["0x02", RLP.encode(fields)]);
}
function _serializeEip2930(transaction, signature) {

@@ -206,3 +245,3 @@ var fields = [

// Legacy and EIP-155 Transactions
if (transaction.type == null) {
if (transaction.type == null || transaction.type === 0) {
if (transaction.accessList != null) {

@@ -217,2 +256,4 @@ logger.throwArgumentError("untyped transactions do not support accessList; include type: 1", "transaction", transaction);

return _serializeEip2930(transaction, signature);
case 2:
return _serializeEip1559(transaction, signature);
default:

@@ -227,2 +268,51 @@ break;

exports.serialize = serialize;
function _parseEipSignature(tx, fields, serialize) {
try {
var recid = handleNumber(fields[0]).toNumber();
if (recid !== 0 && recid !== 1) {
throw new Error("bad recid");
}
tx.v = recid;
}
catch (error) {
logger.throwArgumentError("invalid v for transaction type: 1", "v", fields[0]);
}
tx.r = bytes_1.hexZeroPad(fields[1], 32);
tx.s = bytes_1.hexZeroPad(fields[2], 32);
try {
var digest = keccak256_1.keccak256(serialize(tx));
tx.from = recoverAddress(digest, { r: tx.r, s: tx.s, recoveryParam: tx.v });
}
catch (error) {
console.log(error);
}
}
function _parseEip1559(payload) {
var transaction = RLP.decode(payload.slice(1));
if (transaction.length !== 9 && transaction.length !== 12) {
logger.throwArgumentError("invalid component count for transaction type: 2", "payload", bytes_1.hexlify(payload));
}
var maxPriorityFeePerGas = handleNumber(transaction[2]);
var maxFeePerGas = handleNumber(transaction[3]);
var tx = {
type: 2,
chainId: handleNumber(transaction[0]).toNumber(),
nonce: handleNumber(transaction[1]).toNumber(),
maxPriorityFeePerGas: maxPriorityFeePerGas,
maxFeePerGas: maxFeePerGas,
gasPrice: null,
gasLimit: handleNumber(transaction[4]),
to: handleAddress(transaction[5]),
value: handleNumber(transaction[6]),
data: transaction[7],
accessList: accessListify(transaction[8]),
};
// Unsigned EIP-1559 Transaction
if (transaction.length === 9) {
return tx;
}
tx.hash = keccak256_1.keccak256(payload);
_parseEipSignature(tx, transaction.slice(9), _serializeEip1559);
return tx;
}
function _parseEip2930(payload) {

@@ -242,3 +332,3 @@ var transaction = RLP.decode(payload.slice(1));

data: transaction[6],
accessList: accessListify(transaction[7]),
accessList: accessListify(transaction[7])
};

@@ -249,22 +339,4 @@ // Unsigned EIP-2930 Transaction

}
try {
var recid = handleNumber(transaction[8]).toNumber();
if (recid !== 0 && recid !== 1) {
throw new Error("bad recid");
}
tx.v = recid;
}
catch (error) {
logger.throwArgumentError("invalid v for transaction type: 1", "v", transaction[8]);
}
tx.r = bytes_1.hexZeroPad(transaction[9], 32);
tx.s = bytes_1.hexZeroPad(transaction[10], 32);
try {
var digest = keccak256_1.keccak256(_serializeEip2930(tx));
tx.from = recoverAddress(digest, { r: tx.r, s: tx.s, recoveryParam: tx.v });
}
catch (error) {
console.log(error);
}
tx.hash = keccak256_1.keccak256(payload);
_parseEipSignature(tx, transaction.slice(8), _serializeEip2930);
return tx;

@@ -341,2 +413,4 @@ }

return _parseEip2930(payload);
case 2:
return _parseEip1559(payload);
default:

@@ -343,0 +417,0 @@ break;

{
"author": "Richard Moore <me@ricmoo.com>",
"dependencies": {
"@ethersproject/address": "^5.3.0",
"@ethersproject/bignumber": "^5.3.0",
"@ethersproject/bytes": "^5.3.0",
"@ethersproject/constants": "^5.3.0",
"@ethersproject/keccak256": "^5.3.0",
"@ethersproject/logger": "^5.3.0",
"@ethersproject/properties": "^5.3.0",
"@ethersproject/rlp": "^5.3.0",
"@ethersproject/signing-key": "^5.3.0"
"@ethersproject/address": "^5.4.0",
"@ethersproject/bignumber": "^5.4.0",
"@ethersproject/bytes": "^5.4.0",
"@ethersproject/constants": "^5.4.0",
"@ethersproject/keccak256": "^5.4.0",
"@ethersproject/logger": "^5.4.0",
"@ethersproject/properties": "^5.4.0",
"@ethersproject/rlp": "^5.4.0",
"@ethersproject/signing-key": "^5.4.0"
},

@@ -26,3 +26,3 @@ "description": "Utilities for decoding and encoding Ethereum transaction for ethers.",

],
"gitHead": "4e6d121fb8aa7327290afab7653364be8ddd8d81",
"gitHead": "71b7547f10229f50d8b701611c5e6041b8ed966b",
"keywords": [

@@ -48,5 +48,5 @@ "Ethereum",

"sideEffects": false,
"tarballHash": "0x2c70f8a6fb066417cc37231d2270d8f1ec986d91ef08fa26b064a7480a3dbbe1",
"tarballHash": "0xc29469b44825e6645ec36d604d33c878d036064a10317e6b29f18e9aec2e0c96",
"types": "./lib/index.d.ts",
"version": "5.3.0"
"version": "5.4.0"
}

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

export const version = "transactions/5.3.0";
export const version = "transactions/5.4.0";

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

export enum TransactionTypes {
legacy = 0,
eip2930 = 1,
eip1559 = 2,
};
export type UnsignedTransaction = {

@@ -40,3 +46,9 @@ to?: string;

type?: number | null;
// EIP-2930; Type 1 & EIP-1559; Type 2
accessList?: AccessListish;
// EIP-1559; Type 2
maxPriorityFeePerGas?: BigNumberish;
maxFeePerGas?: BigNumberish;
}

@@ -52,3 +64,3 @@

gasLimit: BigNumber;
gasPrice: BigNumber;
gasPrice?: BigNumber;

@@ -66,4 +78,8 @@ data: string;

// EIP-2930; Type 1
// EIP-2930; Type 1 & EIP-1559; Type 2
accessList?: AccessList;
// EIP-1559; Type 2
maxPriorityFeePerGas?: BigNumber;
maxFeePerGas?: BigNumber;
}

@@ -94,3 +110,3 @@

const allowedTransactionKeys: { [ key: string ]: boolean } = {
chainId: true, data: true, gasLimit: true, gasPrice:true, nonce: true, to: true, value: true
chainId: true, data: true, gasLimit: true, gasPrice:true, nonce: true, to: true, type: true, value: true
}

@@ -155,2 +171,38 @@

function _serializeEip1559(transaction: UnsignedTransaction, signature?: SignatureLike): string {
// If there is an explicit gasPrice, make sure it matches the
// EIP-1559 fees; otherwise they may not understand what they
// think they are setting in terms of fee.
if (transaction.gasPrice != null) {
const gasPrice = BigNumber.from(transaction.gasPrice);
const maxFeePerGas = BigNumber.from(transaction.maxFeePerGas || 0);
if (!gasPrice.eq(maxFeePerGas)) {
logger.throwArgumentError("mismatch EIP-1559 gasPrice != maxFeePerGas", "tx", {
gasPrice, maxFeePerGas
});
}
}
const fields: any = [
formatNumber(transaction.chainId || 0, "chainId"),
formatNumber(transaction.nonce || 0, "nonce"),
formatNumber(transaction.maxPriorityFeePerGas || 0, "maxPriorityFeePerGas"),
formatNumber(transaction.maxFeePerGas || 0, "maxFeePerGas"),
formatNumber(transaction.gasLimit || 0, "gasLimit"),
((transaction.to != null) ? getAddress(transaction.to): "0x"),
formatNumber(transaction.value || 0, "value"),
(transaction.data || "0x"),
(formatAccessList(transaction.accessList || []))
];
if (signature) {
const sig = splitSignature(signature);
fields.push(formatNumber(sig.recoveryParam, "recoveryParam"));
fields.push(stripZeros(sig.r));
fields.push(stripZeros(sig.s));
}
return hexConcat([ "0x02", RLP.encode(fields)]);
}
function _serializeEip2930(transaction: UnsignedTransaction, signature?: SignatureLike): string {

@@ -261,3 +313,3 @@ const fields: any = [

// Legacy and EIP-155 Transactions
if (transaction.type == null) {
if (transaction.type == null || transaction.type === 0) {
if (transaction.accessList != null) {

@@ -273,2 +325,4 @@ logger.throwArgumentError("untyped transactions do not support accessList; include type: 1", "transaction", transaction);

return _serializeEip2930(transaction, signature);
case 2:
return _serializeEip1559(transaction, signature);
default:

@@ -284,2 +338,55 @@ break;

function _parseEipSignature(tx: Transaction, fields: Array<string>, serialize: (tx: UnsignedTransaction) => string): void {
try {
const recid = handleNumber(fields[0]).toNumber();
if (recid !== 0 && recid !== 1) { throw new Error("bad recid"); }
tx.v = recid;
} catch (error) {
logger.throwArgumentError("invalid v for transaction type: 1", "v", fields[0]);
}
tx.r = hexZeroPad(fields[1], 32);
tx.s = hexZeroPad(fields[2], 32);
try {
const digest = keccak256(serialize(tx));
tx.from = recoverAddress(digest, { r: tx.r, s: tx.s, recoveryParam: tx.v });
} catch (error) {
console.log(error);
}
}
function _parseEip1559(payload: Uint8Array): Transaction {
const transaction = RLP.decode(payload.slice(1));
if (transaction.length !== 9 && transaction.length !== 12) {
logger.throwArgumentError("invalid component count for transaction type: 2", "payload", hexlify(payload));
}
const maxPriorityFeePerGas = handleNumber(transaction[2]);
const maxFeePerGas = handleNumber(transaction[3]);
const tx: Transaction = {
type: 2,
chainId: handleNumber(transaction[0]).toNumber(),
nonce: handleNumber(transaction[1]).toNumber(),
maxPriorityFeePerGas: maxPriorityFeePerGas,
maxFeePerGas: maxFeePerGas,
gasPrice: null,
gasLimit: handleNumber(transaction[4]),
to: handleAddress(transaction[5]),
value: handleNumber(transaction[6]),
data: transaction[7],
accessList: accessListify(transaction[8]),
};
// Unsigned EIP-1559 Transaction
if (transaction.length === 9) { return tx; }
tx.hash = keccak256(payload);
_parseEipSignature(tx, transaction.slice(9), _serializeEip1559);
return tx;
}
function _parseEip2930(payload: Uint8Array): Transaction {

@@ -301,3 +408,3 @@ const transaction = RLP.decode(payload.slice(1));

data: transaction[6],
accessList: accessListify(transaction[7]),
accessList: accessListify(transaction[7])
};

@@ -308,21 +415,6 @@

try {
const recid = handleNumber(transaction[8]).toNumber();
if (recid !== 0 && recid !== 1) { throw new Error("bad recid"); }
tx.v = recid;
} catch (error) {
logger.throwArgumentError("invalid v for transaction type: 1", "v", transaction[8]);
}
tx.hash = keccak256(payload);
tx.r = hexZeroPad(transaction[9], 32);
tx.s = hexZeroPad(transaction[10], 32);
_parseEipSignature(tx, transaction.slice(8), _serializeEip2930);
try {
const digest = keccak256(_serializeEip2930(tx));
tx.from = recoverAddress(digest, { r: tx.r, s: tx.s, recoveryParam: tx.v });
} catch (error) {
console.log(error);
}
tx.hash = keccak256(payload);
return tx;

@@ -411,2 +503,4 @@ }

return _parseEip2930(payload);
case 2:
return _parseEip1559(payload);
default:

@@ -413,0 +507,0 @@ break;

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