-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
types.ts
288 lines (253 loc) · 7 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/*
This file is part of web3.js.
web3.js is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
web3.js is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/
import type { HexString, Numbers } from 'web3-types';
import type { Common } from '../common/common.js';
// eslint-disable-next-line require-extensions/require-extensions
import type { Uint8ArrayLike, PrefixedHexString } from '../common/types';
import { Address } from './address.js';
/**
* Can be used in conjunction with {@link Transaction.supports}
* to query on tx capabilities
*/
export enum Capability {
/**
* Tx supports EIP-155 replay protection
* See: [155](https://eips.ethereum.org/EIPS/eip-155) Replay Attack Protection EIP
*/
EIP155ReplayProtection = 155,
/**
* Tx supports EIP-1559 gas fee market mechanism
* See: [1559](https://eips.ethereum.org/EIPS/eip-1559) Fee Market EIP
*/
EIP1559FeeMarket = 1559,
/**
* Tx is a typed transaction as defined in EIP-2718
* See: [2718](https://eips.ethereum.org/EIPS/eip-2718) Transaction Type EIP
*/
EIP2718TypedTransaction = 2718,
/**
* Tx supports access list generation as defined in EIP-2930
* See: [2930](https://eips.ethereum.org/EIPS/eip-2930) Access Lists EIP
*/
EIP2930AccessLists = 2930,
}
/**
* The options for initializing a {@link Transaction}.
*/
export interface TxOptions {
/**
* A {@link Common} object defining the chain and hardfork for the transaction.
*
* Object will be internally copied so that tx behavior don't incidentally
* change on future HF changes.
*
* Default: {@link Common} object set to `mainnet` and the default hardfork as defined in the {@link Common} class.
*
* Current default hardfork: `istanbul`
*/
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.
* It also enables tx hash caching when the `hash()` method is called multiple times.
*
* If you need to deactivate the tx freeze - e.g. because you want to subclass tx and
* add additional properties - it is strongly encouraged that you do the freeze yourself
* within your code instead.
*
* Default: true
*/
freeze?: boolean;
/**
* Allows unlimited contract code-size init while debugging. This (partially) disables EIP-3860.
* Gas cost for initcode size analysis will still be charged. Use with caution.
*/
allowUnlimitedInitCodeSize?: boolean;
}
/*
* Access List types
*/
export type AccessListItem = {
address: PrefixedHexString;
storageKeys: PrefixedHexString[];
};
/*
* An Access List as a tuple of [address: Uint8Array, storageKeys: Uint8Array[]]
*/
export type AccessListUint8ArrayItem = [Uint8Array, Uint8Array[]];
export type AccessListUint8Array = AccessListUint8ArrayItem[];
export type AccessList = AccessListItem[];
export function isAccessListUint8Array(
input: AccessListUint8Array | AccessList,
): input is AccessListUint8Array {
if (input.length === 0) {
return true;
}
const firstItem = input[0];
if (Array.isArray(firstItem)) {
return true;
}
return false;
}
export function isAccessList(input: AccessListUint8Array | AccessList): input is AccessList {
return !isAccessListUint8Array(input); // This is exactly the same method, except the output is negated.
}
export interface ECDSASignature {
v: bigint;
r: Uint8Array;
s: Uint8Array;
}
/**
* Legacy {@link Transaction} Data
*/
export type TxData = {
/**
* The transaction's nonce.
*/
nonce?: Numbers | Uint8Array;
/**
* The transaction's gas price.
*/
// eslint-disable-next-line @typescript-eslint/ban-types
gasPrice?: Numbers | Uint8Array | null;
/**
* The transaction's gas limit.
*/
gasLimit?: Numbers | Uint8Array;
/**
* The transaction's the address is sent to.
*/
to?: Address | Uint8Array | HexString;
/**
* The amount of Ether sent.
*/
value?: Numbers | Uint8Array;
/**
* This will contain the data of the message or the init of a contract.
*/
data?: Uint8ArrayLike;
/**
* EC recovery ID.
*/
v?: Numbers | Uint8Array;
/**
* EC signature parameter.
*/
r?: Numbers | Uint8Array;
/**
* EC signature parameter.
*/
s?: Numbers | Uint8Array;
/**
* The transaction type
*/
type?: Numbers;
};
/**
* {@link AccessListEIP2930Transaction} data.
*/
export interface AccessListEIP2930TxData extends TxData {
/**
* The transaction's chain ID
*/
chainId?: Numbers;
/**
* The access list which contains the addresses/storage slots which the transaction wishes to access
*/
// eslint-disable-next-line @typescript-eslint/ban-types
accessList?: AccessListUint8Array | AccessList | null;
}
/**
* {@link FeeMarketEIP1559Transaction} data.
*/
export interface FeeMarketEIP1559TxData extends AccessListEIP2930TxData {
/**
* The transaction's gas price, inherited from {@link Transaction}. This property is not used for EIP1559
* transactions and should always be undefined for this specific transaction type.
*/
// eslint-disable-next-line @typescript-eslint/ban-types
gasPrice?: never | null;
/**
* The maximum inclusion fee per gas (this fee is given to the miner)
*/
maxPriorityFeePerGas?: Numbers | Uint8Array;
/**
* The maximum total fee
*/
maxFeePerGas?: Numbers | Uint8Array;
}
/**
* Uint8Array values array for a legacy {@link Transaction}
*/
export type TxValuesArray = Uint8Array[];
/**
* Uint8Array values array for an {@link AccessListEIP2930Transaction}
*/
export type AccessListEIP2930ValuesArray = [
Uint8Array,
Uint8Array,
Uint8Array,
Uint8Array,
Uint8Array,
Uint8Array,
Uint8Array,
AccessListUint8Array,
Uint8Array?,
Uint8Array?,
Uint8Array?,
];
/**
* Uint8Array values array for a {@link FeeMarketEIP1559Transaction}
*/
export type FeeMarketEIP1559ValuesArray = [
Uint8Array,
Uint8Array,
Uint8Array,
Uint8Array,
Uint8Array,
Uint8Array,
Uint8Array,
Uint8Array,
AccessListUint8Array,
Uint8Array?,
Uint8Array?,
Uint8Array?,
];
type JsonAccessListItem = { address: string; storageKeys: string[] };
/**
* Generic interface for all tx types with a
* JSON representation of a transaction.
*
* Note that all values are marked as optional
* and not all the values are present on all tx types
* (an EIP1559 tx e.g. lacks a `gasPrice`).
*/
export interface JsonTx {
nonce?: string;
gasPrice?: string;
gasLimit?: string;
to?: string;
data?: string;
v?: string;
r?: string;
s?: string;
value?: string;
chainId?: string;
accessList?: JsonAccessListItem[];
type?: string;
maxPriorityFeePerGas?: string;
maxFeePerGas?: string;
maxFeePerDataGas?: string;
versionedHashes?: string[];
}