@@ -15,29 +15,14 @@ import {
15
15
AccessList ,
16
16
AccessListBuffer ,
17
17
AccessListEIP2930TxData ,
18
+ AccessListEIP2930ValuesArray ,
18
19
AccessListItem ,
19
20
isAccessList ,
20
21
JsonTx ,
21
22
TxOptions ,
23
+ N_DIV_2 ,
22
24
} from './types'
23
25
24
- // secp256k1n/2
25
- const N_DIV_2 = new BN ( '7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0' , 16 )
26
-
27
- type EIP2930ValuesArray = [
28
- Buffer ,
29
- Buffer ,
30
- Buffer ,
31
- Buffer ,
32
- Buffer ,
33
- Buffer ,
34
- Buffer ,
35
- AccessListBuffer ,
36
- Buffer ?,
37
- Buffer ?,
38
- Buffer ?
39
- ]
40
-
41
26
/**
42
27
* Typed transaction with optional access lists
43
28
*
@@ -115,33 +100,33 @@ export default class AccessListEIP2930Transaction extends BaseTransaction<Access
115
100
* chainId, nonce, gasPrice, gasLimit, to, value, data, access_list, yParity (v), senderR (r), senderS (s)
116
101
*/
117
102
public static fromValuesArray ( values : ( Buffer | AccessListBuffer ) [ ] , opts : TxOptions = { } ) {
118
- if ( values . length == 8 || values . length == 11 ) {
119
- const [ chainId , nonce , gasPrice , gasLimit , to , value , data , accessList , v , r , s ] = <
120
- EIP2930ValuesArray
121
- > values
122
- const emptyBuffer = Buffer . from ( [ ] )
123
-
124
- return new AccessListEIP2930Transaction (
125
- {
126
- chainId : new BN ( chainId ) ,
127
- nonce : new BN ( nonce ) ,
128
- gasPrice : new BN ( gasPrice ) ,
129
- gasLimit : new BN ( gasLimit ) ,
130
- to : to && to . length > 0 ? new Address ( to ) : undefined ,
131
- value : new BN ( value ) ,
132
- data : data ?? emptyBuffer ,
133
- accessList : accessList ?? emptyBuffer ,
134
- v : v !== undefined ? new BN ( v ) : undefined , // EIP2930 supports v's with value 0 (empty Buffer)
135
- r : r !== undefined && ! r . equals ( emptyBuffer ) ? new BN ( r ) : undefined ,
136
- s : s !== undefined && ! s . equals ( emptyBuffer ) ? new BN ( s ) : undefined ,
137
- } ,
138
- opts ?? { }
139
- )
140
- } else {
103
+ if ( values . length !== 8 && values . length !== 11 ) {
141
104
throw new Error (
142
105
'Invalid EIP-2930 transaction. Only expecting 8 values (for unsigned tx) or 11 values (for signed tx).'
143
106
)
144
107
}
108
+
109
+ const [ chainId , nonce , gasPrice , gasLimit , to , value , data , accessList , v , r , s ] = <
110
+ AccessListEIP2930ValuesArray
111
+ > values
112
+ const emptyBuffer = Buffer . from ( [ ] )
113
+
114
+ return new AccessListEIP2930Transaction (
115
+ {
116
+ chainId : new BN ( chainId ) ,
117
+ nonce : new BN ( nonce ) ,
118
+ gasPrice : new BN ( gasPrice ) ,
119
+ gasLimit : new BN ( gasLimit ) ,
120
+ to : to && to . length > 0 ? new Address ( to ) : undefined ,
121
+ value : new BN ( value ) ,
122
+ data : data ?? emptyBuffer ,
123
+ accessList : accessList ?? emptyBuffer ,
124
+ v : v !== undefined ? new BN ( v ) : undefined , // EIP2930 supports v's with value 0 (empty Buffer)
125
+ r : r !== undefined && ! r . equals ( emptyBuffer ) ? new BN ( r ) : undefined ,
126
+ s : s !== undefined && ! s . equals ( emptyBuffer ) ? new BN ( s ) : undefined ,
127
+ } ,
128
+ opts
129
+ )
145
130
}
146
131
147
132
/**
@@ -158,8 +143,7 @@ export default class AccessListEIP2930Transaction extends BaseTransaction<Access
158
143
throw new Error ( 'EIP-2930 not enabled on Common' )
159
144
}
160
145
161
- // check the type of AccessList. If it's a JSON-type, we have to convert it to a buffer.
162
-
146
+ // check the type of AccessList. If it's a JSON-type, we have to convert it to a buffer.
163
147
let usedAccessList
164
148
if ( accessList && isAccessList ( accessList ) ) {
165
149
this . AccessListJSON = accessList
@@ -168,7 +152,6 @@ export default class AccessListEIP2930Transaction extends BaseTransaction<Access
168
152
169
153
for ( let i = 0 ; i < accessList . length ; i ++ ) {
170
154
const item : AccessListItem = accessList [ i ]
171
- //const addItem: AccessListBufferItem = []
172
155
const addressBuffer = toBuffer ( item . address )
173
156
const storageItems : Buffer [ ] = [ ]
174
157
for ( let index = 0 ; index < item . storageKeys . length ; index ++ ) {
@@ -208,7 +191,7 @@ export default class AccessListEIP2930Transaction extends BaseTransaction<Access
208
191
throw new Error ( 'The y-parity of the transaction should either be 0 or 1' )
209
192
}
210
193
211
- if ( this . common . gteHardfork ( 'homestead' ) && this . s && this . s . gt ( N_DIV_2 ) ) {
194
+ if ( this . common . gteHardfork ( 'homestead' ) && this . s ? .gt ( N_DIV_2 ) ) {
212
195
throw new Error (
213
196
'Invalid Signature: s-values greater than secp256k1n/2 are considered invalid'
214
197
)
@@ -342,7 +325,7 @@ export default class AccessListEIP2930Transaction extends BaseTransaction<Access
342
325
343
326
// All transaction signatures whose s-value is greater than secp256k1n/2 are considered invalid.
344
327
// TODO: verify if this is the case for EIP-2930
345
- if ( this . common . gteHardfork ( 'homestead' ) && this . s && this . s . gt ( N_DIV_2 ) ) {
328
+ if ( this . common . gteHardfork ( 'homestead' ) && this . s ? .gt ( N_DIV_2 ) ) {
346
329
throw new Error (
347
330
'Invalid Signature: s-values greater than secp256k1n/2 are considered invalid'
348
331
)
0 commit comments