eth 0.5.9 → 0.5.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -186,11 +186,16 @@ module Eth
186
186
  # last but not least, set the type.
187
187
  @type = TYPE_1559
188
188
 
189
- # recover sender address
190
- v = Chain.to_v recovery_id, chain_id
191
- public_key = Signature.recover(unsigned_hash, "#{r.rjust(64, "0")}#{s.rjust(64, "0")}#{v.to_s(16)}", chain_id)
192
- address = Util.public_key_to_address(public_key).to_s
193
- @sender = Tx.sanitize_address address
189
+ unless recovery_id.nil?
190
+ # recover sender address
191
+ v = Chain.to_v recovery_id, chain_id
192
+ public_key = Signature.recover(unsigned_hash, "#{r.rjust(64, "0")}#{s.rjust(64, "0")}#{v.to_s(16)}", chain_id)
193
+ address = Util.public_key_to_address(public_key).to_s
194
+ @sender = Tx.sanitize_address address
195
+ else
196
+ # keep the 'from' field blank
197
+ @sender = Tx.sanitize_address nil
198
+ end
194
199
  end
195
200
 
196
201
  # Creates an unsigned copy of a transaction payload.
@@ -181,11 +181,16 @@ module Eth
181
181
  # last but not least, set the type.
182
182
  @type = TYPE_2930
183
183
 
184
- # recover sender address
185
- v = Chain.to_v recovery_id, chain_id
186
- public_key = Signature.recover(unsigned_hash, "#{r.rjust(64, "0")}#{s.rjust(64, "0")}#{v.to_s(16)}", chain_id)
187
- address = Util.public_key_to_address(public_key).to_s
188
- @sender = Tx.sanitize_address address
184
+ unless recovery_id.nil?
185
+ # recover sender address
186
+ v = Chain.to_v recovery_id, chain_id
187
+ public_key = Signature.recover(unsigned_hash, "#{r.rjust(64, "0")}#{s.rjust(64, "0")}#{v.to_s(16)}", chain_id)
188
+ address = Util.public_key_to_address(public_key).to_s
189
+ @sender = Tx.sanitize_address address
190
+ else
191
+ # keep the 'from' field blank
192
+ @sender = Tx.sanitize_address nil
193
+ end
189
194
  end
190
195
 
191
196
  # Creates an unsigned copy of a transaction payload.
data/lib/eth/tx/legacy.rb CHANGED
@@ -154,13 +154,11 @@ module Eth
154
154
  _set_signature(v, r, s)
155
155
 
156
156
  unless chain_id.nil?
157
-
158
157
  # recover sender address
159
158
  public_key = Signature.recover(unsigned_hash, "#{r.rjust(64, "0")}#{s.rjust(64, "0")}#{v}", chain_id)
160
159
  address = Util.public_key_to_address(public_key).to_s
161
160
  @sender = Tx.sanitize_address address
162
161
  else
163
-
164
162
  # keep the 'from' field blank
165
163
  @sender = Tx.sanitize_address nil
166
164
  end
data/lib/eth/tx.rb CHANGED
@@ -51,6 +51,9 @@ module Eth
51
51
  # The calldata gas cost of a zero byte.
52
52
  COST_ZERO_BYTE = 4.freeze
53
53
 
54
+ # The initcode gas cost for each word (32 bytes).
55
+ COST_INITCODE_WORD = 2.freeze
56
+
54
57
  # The access list gas cost of a storage key as per EIP-2930.
55
58
  COST_STORAGE_KEY = 1_900.freeze
56
59
 
@@ -156,7 +159,7 @@ module Eth
156
159
  end
157
160
 
158
161
  # Estimates intrinsic gas for provided call data (EIP-2028) and
159
- # access lists (EIP-2930).
162
+ # access lists (EIP-2930). Respects initcode word cost (EIP-3860).
160
163
  #
161
164
  # @param data [String] the call data.
162
165
  # @param list [Array] the access list.
@@ -173,6 +176,10 @@ module Eth
173
176
  # count non-zero bytes
174
177
  none = data.size - zero
175
178
  gas += none * COST_NON_ZERO_BYTE
179
+
180
+ # count "words" as per EIP-3860
181
+ word_count = (data.length.to_f / 32.0).ceil
182
+ gas += word_count * COST_INITCODE_WORD
176
183
  end
177
184
  unless list.nil? or list.empty?
178
185
  list.each do |entry|
@@ -187,7 +194,7 @@ module Eth
187
194
  end
188
195
  end
189
196
  end
190
- return gas
197
+ return gas.to_i
191
198
  end
192
199
 
193
200
  # Validates the common transaction fields such as nonce, gas limit,
data/lib/eth/util.rb CHANGED
@@ -28,6 +28,7 @@ module Eth
28
28
  # @return [Eth::Address] an Ethereum address.
29
29
  def public_key_to_address(str)
30
30
  str = hex_to_bin str if hex? str
31
+ str = Secp256k1::PublicKey.from_data(str).uncompressed
31
32
  bytes = keccak256(str[1..-1])[-20..-1]
32
33
  Address.new bin_to_prefixed_hex bytes
33
34
  end
data/lib/eth/version.rb CHANGED
@@ -15,6 +15,15 @@
15
15
  # Provides the {Eth} module.
16
16
  module Eth
17
17
 
18
- # Defines the version of the {Eth} module.
19
- VERSION = "0.5.9".freeze
18
+ # Defines the major version of the {Eth} module.
19
+ MAJOR = 0.freeze
20
+
21
+ # Defines the minor version of the {Eth} module.
22
+ MINOR = 5.freeze
23
+
24
+ # Defines the patch version of the {Eth} module.
25
+ PATCH = 11.freeze
26
+
27
+ # Defines the version string of the {Eth} module.
28
+ VERSION = [MAJOR, MINOR, PATCH].join(".").freeze
20
29
  end
data/lib/eth.rb CHANGED
@@ -32,5 +32,5 @@ require "eth/solidity"
32
32
  require "eth/tx"
33
33
  require "eth/unit"
34
34
  require "eth/util"
35
- require "eth/ens/resolver"
35
+ require "eth/ens"
36
36
  require "eth/version"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.9
4
+ version: 0.5.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Ellis
@@ -9,8 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2022-12-21 00:00:00.000000000 Z
12
+ date: 2023-08-03 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: forwardable
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.3'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.3'
14
28
  - !ruby/object:Gem::Dependency
15
29
  name: keccak
16
30
  requirement: !ruby/object:Gem::Requirement
@@ -45,14 +59,14 @@ dependencies:
45
59
  requirements:
46
60
  - - "~>"
47
61
  - !ruby/object:Gem::Version
48
- version: '5.1'
62
+ version: '6.0'
49
63
  type: :runtime
50
64
  prerelease: false
51
65
  version_requirements: !ruby/object:Gem::Requirement
52
66
  requirements:
53
67
  - - "~>"
54
68
  - !ruby/object:Gem::Version
55
- version: '5.1'
69
+ version: '6.0'
56
70
  - !ruby/object:Gem::Dependency
57
71
  name: openssl
58
72
  requirement: !ruby/object:Gem::Requirement
@@ -105,17 +119,23 @@ files:
105
119
  - ".yardopts"
106
120
  - AUTHORS.txt
107
121
  - CHANGELOG.md
122
+ - CODE_OF_CONDUCT.md
123
+ - CONTRIBUTING.md
108
124
  - Gemfile
109
125
  - LICENSE.txt
110
126
  - README.md
111
127
  - Rakefile
112
- - abis/ens.json
128
+ - SECURITY.md
129
+ - abi/ens_registry.json
130
+ - abi/ens_resolver.json
113
131
  - bin/console
114
132
  - bin/setup
115
133
  - codecov.yml
116
134
  - eth.gemspec
117
135
  - lib/eth.rb
118
136
  - lib/eth/abi.rb
137
+ - lib/eth/abi/decoder.rb
138
+ - lib/eth/abi/encoder.rb
119
139
  - lib/eth/abi/event.rb
120
140
  - lib/eth/abi/type.rb
121
141
  - lib/eth/address.rb
@@ -123,7 +143,6 @@ files:
123
143
  - lib/eth/chain.rb
124
144
  - lib/eth/client.rb
125
145
  - lib/eth/client/http.rb
126
- - lib/eth/client/http_auth.rb
127
146
  - lib/eth/client/ipc.rb
128
147
  - lib/eth/constant.rb
129
148
  - lib/eth/contract.rb
@@ -133,6 +152,8 @@ files:
133
152
  - lib/eth/contract/function_output.rb
134
153
  - lib/eth/contract/initializer.rb
135
154
  - lib/eth/eip712.rb
155
+ - lib/eth/ens.rb
156
+ - lib/eth/ens/coin_type.rb
136
157
  - lib/eth/ens/resolver.rb
137
158
  - lib/eth/key.rb
138
159
  - lib/eth/key/decrypter.rb
@@ -181,7 +202,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
202
  - !ruby/object:Gem::Version
182
203
  version: '0'
183
204
  requirements: []
184
- rubygems_version: 3.2.32
205
+ rubygems_version: 3.3.25
185
206
  signing_key:
186
207
  specification_version: 4
187
208
  summary: Ruby Ethereum library.
data/abis/ens.json DELETED
@@ -1,422 +0,0 @@
1
- [
2
- {
3
- "inputs": [
4
- {
5
- "internalType": "contract ENS",
6
- "name": "_old",
7
- "type": "address"
8
- }
9
- ],
10
- "payable": false,
11
- "stateMutability": "nonpayable",
12
- "type": "constructor"
13
- },
14
- {
15
- "anonymous": false,
16
- "inputs": [
17
- {
18
- "indexed": true,
19
- "internalType": "address",
20
- "name": "owner",
21
- "type": "address"
22
- },
23
- {
24
- "indexed": true,
25
- "internalType": "address",
26
- "name": "operator",
27
- "type": "address"
28
- },
29
- {
30
- "indexed": false,
31
- "internalType": "bool",
32
- "name": "approved",
33
- "type": "bool"
34
- }
35
- ],
36
- "name": "ApprovalForAll",
37
- "type": "event"
38
- },
39
- {
40
- "anonymous": false,
41
- "inputs": [
42
- {
43
- "indexed": true,
44
- "internalType": "bytes32",
45
- "name": "node",
46
- "type": "bytes32"
47
- },
48
- {
49
- "indexed": true,
50
- "internalType": "bytes32",
51
- "name": "label",
52
- "type": "bytes32"
53
- },
54
- {
55
- "indexed": false,
56
- "internalType": "address",
57
- "name": "owner",
58
- "type": "address"
59
- }
60
- ],
61
- "name": "NewOwner",
62
- "type": "event"
63
- },
64
- {
65
- "anonymous": false,
66
- "inputs": [
67
- {
68
- "indexed": true,
69
- "internalType": "bytes32",
70
- "name": "node",
71
- "type": "bytes32"
72
- },
73
- {
74
- "indexed": false,
75
- "internalType": "address",
76
- "name": "resolver",
77
- "type": "address"
78
- }
79
- ],
80
- "name": "NewResolver",
81
- "type": "event"
82
- },
83
- {
84
- "anonymous": false,
85
- "inputs": [
86
- {
87
- "indexed": true,
88
- "internalType": "bytes32",
89
- "name": "node",
90
- "type": "bytes32"
91
- },
92
- {
93
- "indexed": false,
94
- "internalType": "uint64",
95
- "name": "ttl",
96
- "type": "uint64"
97
- }
98
- ],
99
- "name": "NewTTL",
100
- "type": "event"
101
- },
102
- {
103
- "anonymous": false,
104
- "inputs": [
105
- {
106
- "indexed": true,
107
- "internalType": "bytes32",
108
- "name": "node",
109
- "type": "bytes32"
110
- },
111
- {
112
- "indexed": false,
113
- "internalType": "address",
114
- "name": "owner",
115
- "type": "address"
116
- }
117
- ],
118
- "name": "Transfer",
119
- "type": "event"
120
- },
121
- {
122
- "constant": true,
123
- "inputs": [
124
- {
125
- "internalType": "address",
126
- "name": "owner",
127
- "type": "address"
128
- },
129
- {
130
- "internalType": "address",
131
- "name": "operator",
132
- "type": "address"
133
- }
134
- ],
135
- "name": "isApprovedForAll",
136
- "outputs": [
137
- {
138
- "internalType": "bool",
139
- "name": "",
140
- "type": "bool"
141
- }
142
- ],
143
- "payable": false,
144
- "stateMutability": "view",
145
- "type": "function"
146
- },
147
- {
148
- "constant": true,
149
- "inputs": [],
150
- "name": "old",
151
- "outputs": [
152
- {
153
- "internalType": "contract ENS",
154
- "name": "",
155
- "type": "address"
156
- }
157
- ],
158
- "payable": false,
159
- "stateMutability": "view",
160
- "type": "function"
161
- },
162
- {
163
- "constant": true,
164
- "inputs": [
165
- {
166
- "internalType": "bytes32",
167
- "name": "node",
168
- "type": "bytes32"
169
- }
170
- ],
171
- "name": "owner",
172
- "outputs": [
173
- {
174
- "internalType": "address",
175
- "name": "",
176
- "type": "address"
177
- }
178
- ],
179
- "payable": false,
180
- "stateMutability": "view",
181
- "type": "function"
182
- },
183
- {
184
- "constant": true,
185
- "inputs": [
186
- {
187
- "internalType": "bytes32",
188
- "name": "node",
189
- "type": "bytes32"
190
- }
191
- ],
192
- "name": "recordExists",
193
- "outputs": [
194
- {
195
- "internalType": "bool",
196
- "name": "",
197
- "type": "bool"
198
- }
199
- ],
200
- "payable": false,
201
- "stateMutability": "view",
202
- "type": "function"
203
- },
204
- {
205
- "constant": true,
206
- "inputs": [
207
- {
208
- "internalType": "bytes32",
209
- "name": "node",
210
- "type": "bytes32"
211
- }
212
- ],
213
- "name": "resolver",
214
- "outputs": [
215
- {
216
- "internalType": "address",
217
- "name": "",
218
- "type": "address"
219
- }
220
- ],
221
- "payable": false,
222
- "stateMutability": "view",
223
- "type": "function"
224
- },
225
- {
226
- "constant": false,
227
- "inputs": [
228
- {
229
- "internalType": "address",
230
- "name": "operator",
231
- "type": "address"
232
- },
233
- {
234
- "internalType": "bool",
235
- "name": "approved",
236
- "type": "bool"
237
- }
238
- ],
239
- "name": "setApprovalForAll",
240
- "outputs": [],
241
- "payable": false,
242
- "stateMutability": "nonpayable",
243
- "type": "function"
244
- },
245
- {
246
- "constant": false,
247
- "inputs": [
248
- {
249
- "internalType": "bytes32",
250
- "name": "node",
251
- "type": "bytes32"
252
- },
253
- {
254
- "internalType": "address",
255
- "name": "owner",
256
- "type": "address"
257
- }
258
- ],
259
- "name": "setOwner",
260
- "outputs": [],
261
- "payable": false,
262
- "stateMutability": "nonpayable",
263
- "type": "function"
264
- },
265
- {
266
- "constant": false,
267
- "inputs": [
268
- {
269
- "internalType": "bytes32",
270
- "name": "node",
271
- "type": "bytes32"
272
- },
273
- {
274
- "internalType": "address",
275
- "name": "owner",
276
- "type": "address"
277
- },
278
- {
279
- "internalType": "address",
280
- "name": "resolver",
281
- "type": "address"
282
- },
283
- {
284
- "internalType": "uint64",
285
- "name": "ttl",
286
- "type": "uint64"
287
- }
288
- ],
289
- "name": "setRecord",
290
- "outputs": [],
291
- "payable": false,
292
- "stateMutability": "nonpayable",
293
- "type": "function"
294
- },
295
- {
296
- "constant": false,
297
- "inputs": [
298
- {
299
- "internalType": "bytes32",
300
- "name": "node",
301
- "type": "bytes32"
302
- },
303
- {
304
- "internalType": "address",
305
- "name": "resolver",
306
- "type": "address"
307
- }
308
- ],
309
- "name": "setResolver",
310
- "outputs": [],
311
- "payable": false,
312
- "stateMutability": "nonpayable",
313
- "type": "function"
314
- },
315
- {
316
- "constant": false,
317
- "inputs": [
318
- {
319
- "internalType": "bytes32",
320
- "name": "node",
321
- "type": "bytes32"
322
- },
323
- {
324
- "internalType": "bytes32",
325
- "name": "label",
326
- "type": "bytes32"
327
- },
328
- {
329
- "internalType": "address",
330
- "name": "owner",
331
- "type": "address"
332
- }
333
- ],
334
- "name": "setSubnodeOwner",
335
- "outputs": [
336
- {
337
- "internalType": "bytes32",
338
- "name": "",
339
- "type": "bytes32"
340
- }
341
- ],
342
- "payable": false,
343
- "stateMutability": "nonpayable",
344
- "type": "function"
345
- },
346
- {
347
- "constant": false,
348
- "inputs": [
349
- {
350
- "internalType": "bytes32",
351
- "name": "node",
352
- "type": "bytes32"
353
- },
354
- {
355
- "internalType": "bytes32",
356
- "name": "label",
357
- "type": "bytes32"
358
- },
359
- {
360
- "internalType": "address",
361
- "name": "owner",
362
- "type": "address"
363
- },
364
- {
365
- "internalType": "address",
366
- "name": "resolver",
367
- "type": "address"
368
- },
369
- {
370
- "internalType": "uint64",
371
- "name": "ttl",
372
- "type": "uint64"
373
- }
374
- ],
375
- "name": "setSubnodeRecord",
376
- "outputs": [],
377
- "payable": false,
378
- "stateMutability": "nonpayable",
379
- "type": "function"
380
- },
381
- {
382
- "constant": false,
383
- "inputs": [
384
- {
385
- "internalType": "bytes32",
386
- "name": "node",
387
- "type": "bytes32"
388
- },
389
- {
390
- "internalType": "uint64",
391
- "name": "ttl",
392
- "type": "uint64"
393
- }
394
- ],
395
- "name": "setTTL",
396
- "outputs": [],
397
- "payable": false,
398
- "stateMutability": "nonpayable",
399
- "type": "function"
400
- },
401
- {
402
- "constant": true,
403
- "inputs": [
404
- {
405
- "internalType": "bytes32",
406
- "name": "node",
407
- "type": "bytes32"
408
- }
409
- ],
410
- "name": "ttl",
411
- "outputs": [
412
- {
413
- "internalType": "uint64",
414
- "name": "",
415
- "type": "uint64"
416
- }
417
- ],
418
- "payable": false,
419
- "stateMutability": "view",
420
- "type": "function"
421
- }
422
- ]