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 6.0.0-beta.1 to 6.0.0-beta.2

lib/address.d.ts

2

lib/_version.d.ts

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

export declare const version = "@ethersproject/transactions@6.0.0-beta.1";
export declare const version = "@ethersproject/transactions@6.0.0-beta.2";
//# sourceMappingURL=_version.d.ts.map

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

export const version = "@ethersproject/transactions@6.0.0-beta.1";
export const version = "@ethersproject/transactions@6.0.0-beta.2";
//# sourceMappingURL=_version.js.map
export { accessListify } from "./accesslist.js";
export { computeAddress, recoverAddress } from "./address.js";
export { Transaction } from "./transaction.js";

@@ -3,0 +4,0 @@ export type { AccessList, AccessListSet, AccessListish } from "./accesslist.js";

export { accessListify } from "./accesslist.js";
export { computeAddress, recoverAddress } from "./address.js";
export { Transaction } from "./transaction.js";
//# sourceMappingURL=index.js.map

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

import { BytesLike } from "@ethersproject/bytes";
import { Signature, SignatureLike } from "@ethersproject/signing-key";
import type { BigNumberish } from "@ethersproject/logger";
import { Signature } from "@ethersproject/signing-key";
import type { BigNumberish, BytesLike } from "@ethersproject/logger";
import type { Freezable, Frozen } from "@ethersproject/properties";
import type { SignatureLike } from "@ethersproject/signing-key";
import type { AccessList, AccessListish } from "./accesslist.js";

@@ -25,4 +25,20 @@ export interface TransactionLike<A = string> {

typeName: string;
from: string;
signature: Signature;
}
export interface LegacyTransaction extends Transaction {
type: 0;
gasPrice: bigint;
}
export interface BerlinTransaction extends Transaction {
type: 1;
gasPrice: bigint;
accessList: AccessList;
}
export interface LondonTransaction extends Transaction {
type: 2;
maxFeePerGas: bigint;
maxPriorityFeePerGas: bigint;
accessList: AccessList;
}
export declare class Transaction implements Freezable<Transaction>, TransactionLike<string> {

@@ -64,2 +80,5 @@ #private;

inferTypes(): Array<number>;
isLegacy(): this is LegacyTransaction;
isBerlin(): this is BerlinTransaction;
isLondon(): this is LondonTransaction;
clone(): Transaction;

@@ -66,0 +85,0 @@ freeze(): Frozen<Transaction>;

@@ -14,11 +14,55 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {

import { getAddress } from "@ethersproject/address";
import { arrayify, concat, hexlify } from "@ethersproject/bytes";
import { arrayify, concat, hexlify, zeroPadValue } from "@ethersproject/bytes";
import { keccak256 } from "@ethersproject/crypto";
import { toArray } from "@ethersproject/math";
import { getStore, setStore } from "@ethersproject/properties";
import { encodeRlp } from "@ethersproject/rlp";
import { decodeRlp, encodeRlp } from "@ethersproject/rlp";
import { Signature } from "@ethersproject/signing-key";
import { accessListify } from "./accesslist.js";
import { recoverAddress } from "./address.js";
import { logger } from "./logger.js";
const BN_0 = BigInt(0);
const BN_2 = BigInt(2);
const BN_27 = BigInt(27);
const BN_28 = BigInt(28);
const BN_35 = BigInt(35);
const BN_MAX_UINT = BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
function handleAddress(value) {
if (value === "0x") {
return null;
}
return getAddress(value);
}
function handleData(value, param) {
try {
return hexlify(value);
}
catch (error) {
return logger.throwArgumentError("invalid data", param, value);
}
}
function handleAccessList(value, param) {
try {
return accessListify(value);
}
catch (error) {
return logger.throwArgumentError("invalid accessList", param, value);
}
}
function handleNumber(_value, param) {
if (_value === "0x") {
return 0;
}
return logger.getNumber(_value, param);
}
function handleUint(_value, param) {
if (_value === "0x") {
return BN_0;
}
const value = logger.getBigInt(_value, param);
if (value > BN_MAX_UINT) {
logger.throwArgumentError("value exceeds uint size", param, value);
}
return value;
}
function formatNumber(_value, name) {

@@ -36,3 +80,46 @@ const value = logger.getBigInt(_value, "value");

function _parseLegacy(data) {
return {};
const fields = decodeRlp(data);
if (!Array.isArray(fields) || (fields.length !== 9 && fields.length !== 6)) {
return logger.throwArgumentError("invalid field count for legacy transaction", "data", data);
}
const tx = {
type: 0,
nonce: handleNumber(fields[0], "nonce"),
gasPrice: handleUint(fields[1], "gasPrice"),
gasLimit: handleUint(fields[2], "gasLimit"),
to: handleAddress(fields[3]),
value: handleUint(fields[4], "value"),
data: handleData(fields[5], "dta"),
chainId: BN_0
};
// Legacy unsigned transaction
if (fields.length === 6) {
return tx;
}
const v = handleUint(fields[6], "v");
const r = handleUint(fields[7], "r");
const s = handleUint(fields[8], "s");
if (r === BN_0 && s === BN_0) {
// EIP-155 unsigned transaction
tx.chainId = v;
}
else {
// Compute the EIP-155 chain ID (or 0 for legacy)
let chainId = (v - BN_35) / BN_2;
if (chainId < BN_0) {
chainId = BN_0;
}
tx.chainId = chainId;
// Signed Legacy Transaction
if (chainId === BN_0 && (v < BN_27 || v > BN_28)) {
logger.throwArgumentError("non-canonical legacy v", "v", fields[6]);
}
tx.signature = Signature.from({
r: zeroPadValue(fields[7], 32),
s: zeroPadValue(fields[8], 32),
v
});
tx.hash = keccak256(data);
}
return tx;
}

@@ -88,14 +175,47 @@ function _serializeLegacy(tx, sig) {

}
function _parseEipSignature(tx, fields, serialize) {
let yParity;
try {
yParity = handleNumber(fields[0], "yParity");
if (yParity !== 0 && yParity !== 1) {
throw new Error("bad yParity");
}
}
catch (error) {
return logger.throwArgumentError("invalid yParity", "yParity", fields[0]);
}
const r = zeroPadValue(fields[1], 32);
const s = zeroPadValue(fields[2], 32);
const signature = Signature.from({ r, s, yParity });
tx.signature = signature;
}
function _parseEip1559(data) {
throw new Error("@TODO");
const fields = decodeRlp(logger.getBytes(data).slice(1));
if (!Array.isArray(fields) || (fields.length !== 9 && fields.length !== 12)) {
logger.throwArgumentError("invalid field count for transaction type: 2", "data", hexlify(data));
}
const maxPriorityFeePerGas = handleUint(fields[2], "maxPriorityFeePerGas");
const maxFeePerGas = handleUint(fields[3], "maxFeePerGas");
const tx = {
type: 2,
chainId: handleUint(fields[0], "chainId"),
nonce: handleNumber(fields[1], "nonce"),
maxPriorityFeePerGas: maxPriorityFeePerGas,
maxFeePerGas: maxFeePerGas,
gasPrice: null,
gasLimit: handleUint(fields[4], "gasLimit"),
to: handleAddress(fields[5]),
value: handleUint(fields[6], "value"),
data: handleData(fields[7], "data"),
accessList: handleAccessList(fields[8], "accessList"),
};
// Unsigned EIP-1559 Transaction
if (fields.length === 9) {
return tx;
}
tx.hash = keccak256(data);
_parseEipSignature(tx, fields.slice(9), _serializeEip1559);
return tx;
}
function _serializeEip1559(tx, sig) {
// 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 (tx.gasPrice != null) {
// if (tx.gasPrice !== (tx.maxFeePerGas || BN_0)) {
// logger.throwArgumentError("mismatch EIP-1559 gasPrice != maxFeePerGas", "tx", tx);
// }
//}
const fields = [

@@ -120,3 +240,24 @@ formatNumber(tx.chainId || 0, "chainId"),

function _parseEip2930(data) {
throw new Error("@TODO");
const fields = decodeRlp(logger.getBytes(data).slice(1));
if (!Array.isArray(fields) || (fields.length !== 8 && fields.length !== 11)) {
logger.throwArgumentError("invalid field count for transaction type: 1", "data", hexlify(data));
}
const tx = {
type: 1,
chainId: handleUint(fields[0], "chainId"),
nonce: handleNumber(fields[1], "nonce"),
gasPrice: handleUint(fields[2], "gasPrice"),
gasLimit: handleUint(fields[3], "gasLimit"),
to: handleAddress(fields[4]),
value: handleUint(fields[5], "value"),
data: handleData(fields[6], "data"),
accessList: handleAccessList(fields[7], "accessList")
};
// Unsigned EIP-2930 Transaction
if (fields.length === 8) {
return tx;
}
tx.hash = keccak256(data);
_parseEipSignature(tx, fields.slice(8), _serializeEip2930);
return tx;
}

@@ -192,19 +333,2 @@ function _serializeEip2930(tx, sig) {

}
/*
detectType(): number {
const hasFee = (this.maxFeePerGas != null) || (this.maxPriorityFeePerGas != null);
const hasAccessList = (this.accessList != null);
const hasLegacy = (this.gasPrice != null);
if (hasLegacy) {
if (hasFee) {
throw new Error("cannot mix legacy and london properties");
}
if (hasAccessList) { return 1; }
return 0;
}
return 2;
}
*/
get to() { return getStore(__classPrivateFieldGet(this, _Transaction_props, "f"), "to"); }

@@ -218,13 +342,31 @@ set to(value) {

set gasLimit(value) { setStore(__classPrivateFieldGet(this, _Transaction_props, "f"), "gasLimit", logger.getBigInt(value)); }
get gasPrice() { return getStore(__classPrivateFieldGet(this, _Transaction_props, "f"), "gasPrice"); }
get gasPrice() {
const value = getStore(__classPrivateFieldGet(this, _Transaction_props, "f"), "gasPrice");
if (value == null && (this.type === 0 || this.type === 1)) {
return BN_0;
}
return value;
}
set gasPrice(value) {
setStore(__classPrivateFieldGet(this, _Transaction_props, "f"), "gasPrice", (value == null) ? null : logger.getBigInt(value));
setStore(__classPrivateFieldGet(this, _Transaction_props, "f"), "gasPrice", (value == null) ? null : logger.getBigInt(value, "gasPrice"));
}
get maxPriorityFeePerGas() { return getStore(__classPrivateFieldGet(this, _Transaction_props, "f"), "maxPriorityFeePerGas"); }
get maxPriorityFeePerGas() {
const value = getStore(__classPrivateFieldGet(this, _Transaction_props, "f"), "maxPriorityFeePerGas");
if (value == null && this.type === 2) {
return BN_0;
}
return value;
}
set maxPriorityFeePerGas(value) {
setStore(__classPrivateFieldGet(this, _Transaction_props, "f"), "maxPriorityFeePerGas", (value == null) ? null : logger.getBigInt(value));
setStore(__classPrivateFieldGet(this, _Transaction_props, "f"), "maxPriorityFeePerGas", (value == null) ? null : logger.getBigInt(value, "maxPriorityFeePerGas"));
}
get maxFeePerGas() { return getStore(__classPrivateFieldGet(this, _Transaction_props, "f"), "maxFeePerGas"); }
get maxFeePerGas() {
const value = getStore(__classPrivateFieldGet(this, _Transaction_props, "f"), "maxFeePerGas");
if (value == null && this.type === 2) {
return BN_0;
}
return value;
}
set maxFeePerGas(value) {
setStore(__classPrivateFieldGet(this, _Transaction_props, "f"), "maxFeePerGas", (value == null) ? null : logger.getBigInt(value));
setStore(__classPrivateFieldGet(this, _Transaction_props, "f"), "maxFeePerGas", (value == null) ? null : logger.getBigInt(value, "maxFeePerGas"));
}

@@ -235,3 +377,3 @@ get data() { return getStore(__classPrivateFieldGet(this, _Transaction_props, "f"), "data"); }

set value(value) {
setStore(__classPrivateFieldGet(this, _Transaction_props, "f"), "value", logger.getBigInt(value));
setStore(__classPrivateFieldGet(this, _Transaction_props, "f"), "value", logger.getBigInt(value, "value"));
}

@@ -244,3 +386,9 @@ get chainId() { return getStore(__classPrivateFieldGet(this, _Transaction_props, "f"), "chainId"); }

}
get accessList() { return getStore(__classPrivateFieldGet(this, _Transaction_props, "f"), "accessList") || null; }
get accessList() {
const value = getStore(__classPrivateFieldGet(this, _Transaction_props, "f"), "accessList") || null;
if (value == null && (this.type === 1 || this.type === 2)) {
return [];
}
return value;
}
set accessList(value) {

@@ -262,4 +410,3 @@ setStore(__classPrivateFieldGet(this, _Transaction_props, "f"), "accessList", (value == null) ? null : accessListify(value));

}
// use ecomputeAddress(this.fromPublicKey);
return "";
return recoverAddress(this.unsignedSerialized, this.signature);
}

@@ -295,5 +442,2 @@ get fromPublicKey() {

get unsignedSerialized() {
if (this.signature != null) {
throw new Error("cannot serialize unsigned transaction; maybe you meant .unsignedSerialized");
}
const types = this.inferTypes();

@@ -322,3 +466,3 @@ if (types.length !== 1) {

//}
if (!!this.maxFeePerGas && !!this.maxPriorityFeePerGas) {
if (this.maxFeePerGas != null && this.maxPriorityFeePerGas != null) {
if (this.maxFeePerGas < this.maxPriorityFeePerGas) {

@@ -365,2 +509,5 @@ throw new Error("priorityFee cannot be more than maxFee");

}
isLegacy() { return (this.type === 0); }
isBerlin() { return (this.type === 1); }
isLondon() { return (this.type === 2); }
clone() {

@@ -392,4 +539,4 @@ return Transaction.from(this);

switch (payload[0]) {
case 1: return Transaction.from(_parseEip2930(payload.slice(1)));
case 2: return Transaction.from(_parseEip1559(payload.slice(1)));
case 1: return Transaction.from(_parseEip2930(payload));
case 2: return Transaction.from(_parseEip1559(payload));
}

@@ -435,5 +582,22 @@ throw new Error("unsupported transaction type");

}
// Should these be checked?? Should from be allowed if there is no signature?
// from?: null | A;
// hash?: null | string;
if ("hash" in tx) {
if (result.isSigned()) {
if (result.hash !== tx.hash) {
throw new Error("hash mismatch");
}
}
else {
throw new Error("unsigned transaction cannot have a hashs");
}
}
if ("from" in tx) {
if (result.isSigned()) {
if (result.from.toLowerCase() !== (tx.from || "").toLowerCase()) {
throw new Error("from mismatch");
}
}
else {
throw new Error("unsigned transaction cannot have a from");
}
}
return result;

@@ -440,0 +604,0 @@ }

@@ -18,3 +18,3 @@ {

"ethereum": "donations.ethers.eth",
"gitHead": "77f691b3bc3a6387a5184ec9b1779faab4bcb30d",
"gitHead": "4fcde0967317451fac6cec6addba8258f98c14b5",
"keywords": [

@@ -40,6 +40,6 @@ "Ethereum",

"sideEffects": false,
"tarballHash": "0x9e2724319d7734e70945de4e7922130ca177980eafd3cabb09b5307632fc9585",
"tarballHash": "0xb35a6c4780241fe968ad31bd8563364c0fa386e5a8537653156433588a27aff4",
"type": "module",
"types": "./lib/index.d.ts",
"version": "6.0.0-beta.1"
"version": "6.0.0-beta.2"
}

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

export const version = "@ethersproject/transactions@6.0.0-beta.1";
export const version = "@ethersproject/transactions@6.0.0-beta.2";
export { accessListify } from "./accesslist.js";
export { computeAddress, recoverAddress } from "./address.js";
export { Transaction } from "./transaction.js";

@@ -3,0 +4,0 @@

import { getAddress } from "@ethersproject/address";
import { arrayify, BytesLike, concat, hexlify } from "@ethersproject/bytes";
import { arrayify, concat, hexlify, zeroPadValue } from "@ethersproject/bytes";
import { keccak256 } from "@ethersproject/crypto";
import { toArray } from "@ethersproject/math";
import { getStore, setStore } from "@ethersproject/properties";
import { encodeRlp } from "@ethersproject/rlp";
import { Signature, SignatureLike } from "@ethersproject/signing-key";
import { decodeRlp, encodeRlp } from "@ethersproject/rlp";
import { Signature } from "@ethersproject/signing-key";
import { accessListify } from "./accesslist.js";
import { recoverAddress } from "./address.js";
import { logger } from "./logger.js";
import type { BigNumberish } from "@ethersproject/logger";
import type { BigNumberish, BytesLike } from "@ethersproject/logger";
import type { Freezable, Frozen } from "@ethersproject/properties";
import type { SignatureLike } from "@ethersproject/signing-key";

@@ -20,2 +22,7 @@ import type { AccessList, AccessListish } from "./accesslist.js";

const BN_0 = BigInt(0);
const BN_2 = BigInt(2);
const BN_27 = BigInt(27)
const BN_28 = BigInt(28)
const BN_35 = BigInt(35);
const BN_MAX_UINT = BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");

@@ -47,2 +54,35 @@ export interface TransactionLike<A = string> {

function handleAddress(value: string): null | string {
if (value === "0x") { return null; }
return getAddress(value);
}
function handleData(value: string, param: string): string {
try {
return hexlify(value);
} catch (error) {
return logger.throwArgumentError("invalid data", param, value);
}
}
function handleAccessList(value: any, param: string): AccessList {
try {
return accessListify(value);
} catch (error) {
return logger.throwArgumentError("invalid accessList", param, value);
}
}
function handleNumber(_value: string, param: string): number {
if (_value === "0x") { return 0; }
return logger.getNumber(_value, param);
}
function handleUint(_value: string, param: string): bigint {
if (_value === "0x") { return BN_0; }
const value = logger.getBigInt(_value, param);
if (value > BN_MAX_UINT) { logger.throwArgumentError("value exceeds uint size", param, value); }
return value;
}
function formatNumber(_value: BigNumberish, name: string): Uint8Array {

@@ -62,3 +102,52 @@ const value = logger.getBigInt(_value, "value");

function _parseLegacy(data: Uint8Array): TransactionLike {
return { };
const fields: any = decodeRlp(data);
if (!Array.isArray(fields) || (fields.length !== 9 && fields.length !== 6)) {
return logger.throwArgumentError("invalid field count for legacy transaction", "data", data);
}
const tx: TransactionLike = {
type: 0,
nonce: handleNumber(fields[0], "nonce"),
gasPrice: handleUint(fields[1], "gasPrice"),
gasLimit: handleUint(fields[2], "gasLimit"),
to: handleAddress(fields[3]),
value: handleUint(fields[4], "value"),
data: handleData(fields[5], "dta"),
chainId: BN_0
};
// Legacy unsigned transaction
if (fields.length === 6) { return tx; }
const v = handleUint(fields[6], "v");
const r = handleUint(fields[7], "r");
const s = handleUint(fields[8], "s");
if (r === BN_0 && s === BN_0) {
// EIP-155 unsigned transaction
tx.chainId = v;
} else {
// Compute the EIP-155 chain ID (or 0 for legacy)
let chainId = (v - BN_35) / BN_2;
if (chainId < BN_0) { chainId = BN_0; }
tx.chainId = chainId
// Signed Legacy Transaction
if (chainId === BN_0 && (v < BN_27 || v > BN_28)) {
logger.throwArgumentError("non-canonical legacy v", "v", fields[6]);
}
tx.signature = Signature.from({
r: zeroPadValue(fields[7], 32),
s: zeroPadValue(fields[8], 32),
v
});
tx.hash = keccak256(data);
}
return tx;
}

@@ -120,15 +209,52 @@

function _parseEipSignature(tx: TransactionLike, fields: Array<string>, serialize: (tx: TransactionLike) => string): void {
let yParity: number;
try {
yParity = handleNumber(fields[0], "yParity");
if (yParity !== 0 && yParity !== 1) { throw new Error("bad yParity"); }
} catch (error) {
return logger.throwArgumentError("invalid yParity", "yParity", fields[0]);
}
const r = zeroPadValue(fields[1], 32);
const s = zeroPadValue(fields[2], 32);
const signature = Signature.from({ r, s, yParity });
tx.signature = signature;
}
function _parseEip1559(data: Uint8Array): TransactionLike {
throw new Error("@TODO");
const fields: any = decodeRlp(logger.getBytes(data).slice(1));
if (!Array.isArray(fields) || (fields.length !== 9 && fields.length !== 12)) {
logger.throwArgumentError("invalid field count for transaction type: 2", "data", hexlify(data));
}
const maxPriorityFeePerGas = handleUint(fields[2], "maxPriorityFeePerGas");
const maxFeePerGas = handleUint(fields[3], "maxFeePerGas");
const tx: TransactionLike = {
type: 2,
chainId: handleUint(fields[0], "chainId"),
nonce: handleNumber(fields[1], "nonce"),
maxPriorityFeePerGas: maxPriorityFeePerGas,
maxFeePerGas: maxFeePerGas,
gasPrice: null,
gasLimit: handleUint(fields[4], "gasLimit"),
to: handleAddress(fields[5]),
value: handleUint(fields[6], "value"),
data: handleData(fields[7], "data"),
accessList: handleAccessList(fields[8], "accessList"),
};
// Unsigned EIP-1559 Transaction
if (fields.length === 9) { return tx; }
tx.hash = keccak256(data);
_parseEipSignature(tx, fields.slice(9), _serializeEip1559);
return tx;
}
function _serializeEip1559(tx: Transaction, sig?: Signature): 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 (tx.gasPrice != null) {
// if (tx.gasPrice !== (tx.maxFeePerGas || BN_0)) {
// logger.throwArgumentError("mismatch EIP-1559 gasPrice != maxFeePerGas", "tx", tx);
// }
//}
function _serializeEip1559(tx: TransactionLike, sig?: Signature): string {
const fields: Array<any> = [

@@ -156,6 +282,31 @@ formatNumber(tx.chainId || 0, "chainId"),

function _parseEip2930(data: Uint8Array): TransactionLike {
throw new Error("@TODO");
const fields: any = decodeRlp(logger.getBytes(data).slice(1));
if (!Array.isArray(fields) || (fields.length !== 8 && fields.length !== 11)) {
logger.throwArgumentError("invalid field count for transaction type: 1", "data", hexlify(data));
}
const tx: TransactionLike = {
type: 1,
chainId: handleUint(fields[0], "chainId"),
nonce: handleNumber(fields[1], "nonce"),
gasPrice: handleUint(fields[2], "gasPrice"),
gasLimit: handleUint(fields[3], "gasLimit"),
to: handleAddress(fields[4]),
value: handleUint(fields[5], "value"),
data: handleData(fields[6], "data"),
accessList: handleAccessList(fields[7], "accessList")
};
// Unsigned EIP-2930 Transaction
if (fields.length === 8) { return tx; }
tx.hash = keccak256(data);
_parseEipSignature(tx, fields.slice(8), _serializeEip2930);
return tx;
}
function _serializeEip2930(tx: Transaction, sig?: Signature): string {
function _serializeEip2930(tx: TransactionLike, sig?: Signature): string {
const fields: any = [

@@ -184,5 +335,24 @@ formatNumber(tx.chainId || 0, "chainId"),

typeName: string;
from: string;
signature: Signature;
}
export interface LegacyTransaction extends Transaction {
type: 0;
gasPrice: bigint;
}
export interface BerlinTransaction extends Transaction {
type: 1;
gasPrice: bigint;
accessList: AccessList;
}
export interface LondonTransaction extends Transaction {
type: 2;
maxFeePerGas: bigint;
maxPriorityFeePerGas: bigint;
accessList: AccessList;
}
export class Transaction implements Freezable<Transaction>, TransactionLike<string> {

@@ -234,20 +404,2 @@ #props: {

/*
detectType(): number {
const hasFee = (this.maxFeePerGas != null) || (this.maxPriorityFeePerGas != null);
const hasAccessList = (this.accessList != null);
const hasLegacy = (this.gasPrice != null);
if (hasLegacy) {
if (hasFee) {
throw new Error("cannot mix legacy and london properties");
}
if (hasAccessList) { return 1; }
return 0;
}
return 2;
}
*/
get to(): null | string { return getStore(this.#props, "to"); }

@@ -264,15 +416,27 @@ set to(value: null | string) {

get gasPrice(): null | bigint { return getStore(this.#props, "gasPrice"); }
get gasPrice(): null | bigint {
const value = getStore(this.#props, "gasPrice");
if (value == null && (this.type === 0 || this.type === 1)) { return BN_0; }
return value;
}
set gasPrice(value: null | BigNumberish) {
setStore(this.#props, "gasPrice", (value == null) ? null: logger.getBigInt(value));
setStore(this.#props, "gasPrice", (value == null) ? null: logger.getBigInt(value, "gasPrice"));
}
get maxPriorityFeePerGas(): null | bigint { return getStore(this.#props, "maxPriorityFeePerGas"); }
get maxPriorityFeePerGas(): null | bigint {
const value = getStore(this.#props, "maxPriorityFeePerGas");
if (value == null && this.type === 2) { return BN_0; }
return value;
}
set maxPriorityFeePerGas(value: null | BigNumberish) {
setStore(this.#props, "maxPriorityFeePerGas", (value == null) ? null: logger.getBigInt(value));
setStore(this.#props, "maxPriorityFeePerGas", (value == null) ? null: logger.getBigInt(value, "maxPriorityFeePerGas"));
}
get maxFeePerGas(): null | bigint { return getStore(this.#props, "maxFeePerGas"); }
get maxFeePerGas(): null | bigint {
const value = getStore(this.#props, "maxFeePerGas");
if (value == null && this.type === 2) { return BN_0; }
return value;
}
set maxFeePerGas(value: null | BigNumberish) {
setStore(this.#props, "maxFeePerGas", (value == null) ? null: logger.getBigInt(value));
setStore(this.#props, "maxFeePerGas", (value == null) ? null: logger.getBigInt(value, "maxFeePerGas"));
}

@@ -285,3 +449,3 @@

set value(value: BigNumberish) {
setStore(this.#props, "value", logger.getBigInt(value));
setStore(this.#props, "value", logger.getBigInt(value, "value"));
}

@@ -297,3 +461,7 @@

get accessList(): null | AccessList { return getStore(this.#props, "accessList") || null; }
get accessList(): null | AccessList {
const value = getStore(this.#props, "accessList") || null;
if (value == null && (this.type === 1 || this.type === 2)) { return [ ]; }
return value;
}
set accessList(value: null | AccessListish) {

@@ -333,4 +501,3 @@ setStore(this.#props, "accessList", (value == null) ? null: accessListify(value));

if (this.signature == null) { return null; }
// use ecomputeAddress(this.fromPublicKey);
return "";
return recoverAddress(this.unsignedSerialized, this.signature);
}

@@ -371,6 +538,2 @@

get unsignedSerialized(): string {
if (this.signature != null) {
throw new Error("cannot serialize unsigned transaction; maybe you meant .unsignedSerialized");
}
const types = this.inferTypes();

@@ -405,3 +568,3 @@ if (types.length !== 1) {

if (!!this.maxFeePerGas && !!this.maxPriorityFeePerGas) {
if (this.maxFeePerGas != null && this.maxPriorityFeePerGas != null) {
if (this.maxFeePerGas < this.maxPriorityFeePerGas) {

@@ -451,2 +614,6 @@ throw new Error("priorityFee cannot be more than maxFee");

isLegacy(): this is LegacyTransaction { return (this.type === 0); }
isBerlin(): this is BerlinTransaction { return (this.type === 1); }
isLondon(): this is LondonTransaction { return (this.type === 2); }
clone(): Transaction {

@@ -485,4 +652,4 @@ return Transaction.from(this);

switch(payload[0]) {
case 1: return Transaction.from(_parseEip2930(payload.slice(1)));
case 2: return Transaction.from(_parseEip1559(payload.slice(1)));
case 1: return Transaction.from(_parseEip2930(payload));
case 2: return Transaction.from(_parseEip1559(payload));
}

@@ -507,8 +674,20 @@

// Should these be checked?? Should from be allowed if there is no signature?
// from?: null | A;
// hash?: null | string;
if ("hash" in tx) {
if (result.isSigned()) {
if (result.hash !== tx.hash) { throw new Error("hash mismatch"); }
} else {
throw new Error("unsigned transaction cannot have a hashs");
}
}
if ("from" in tx) {
if (result.isSigned()) {
if (result.from.toLowerCase() !== (tx.from || "").toLowerCase()) { throw new Error("from mismatch"); }
} else {
throw new Error("unsigned transaction cannot have a from");
}
}
return result;
}
}

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