eth 0.4.8 → 0.4.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7e801e6af9201a0653adfca521abd33b5f2dab92
4
- data.tar.gz: e0ed95cce6e8f25091ec6253e18654d539e64b2a
2
+ SHA256:
3
+ metadata.gz: c2145cbe87b192081aa7f1ef32e8e92669c089e61e6d9d7221a1f18885c7bbcd
4
+ data.tar.gz: c20ed4ac5450ad6cfae066f58e7bb7a193e6c6a4a29ce9a1d2be71f5d2cbaf7b
5
5
  SHA512:
6
- metadata.gz: c3cfeb4cb2d190095452908c1d40b341b808e10c03711c4a96e556b381dec18a6ac92c19f0021a35b85574fdadeb6d7c185226aff356f297788faef18dabbab3
7
- data.tar.gz: f07015333af071a10c5a59a254293902ac9afe6e72ddcc27d782e69f97a19afcdad6e651bb80e7ad33a9033f50503568d9e865414108dcacb4117b8cdb37e241
6
+ metadata.gz: 492fcfbda0bfebacc44d0b684350d3e73e68a8449461cc8fcd97364b0e4be06909c2eff0bc86da7f127aceb8b0109f4ad86edf716b65e0e00b701d7f29f17c4e
7
+ data.tar.gz: 2450ae894c0324ecefd737105cb47275406a816ba998423bd4562539c1c1278062f564b97b725dc050e1e2c192260f19daad2f4e6a67d5aa8505a68332dd51b2
@@ -4,6 +4,18 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/).
6
6
 
7
+ ### Unreleased
8
+
9
+ ## [0.4.10]
10
+
11
+ ### Changed
12
+ - Changed Eth::Configuration.default_chain_id back to .chain_id for dependent libraries.
13
+
14
+ ## [0.4.9]
15
+
16
+ ### Changed
17
+ - [escoffon](https://github.com/escoffon) added support for chain IDs larger than 120.
18
+
7
19
  ## [0.4.8]
8
20
 
9
21
  ### Added
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_dependency 'ffi', '~> 1.0'
24
24
  spec.add_dependency 'money-tree', '~> 0.10.0'
25
25
  spec.add_dependency 'rlp', '~> 0.7.3'
26
- spec.add_dependency 'scrypt', '~> 3.0.5'
26
+ spec.add_dependency 'scrypt', '~> 3.0.6'
27
27
 
28
28
  spec.add_development_dependency 'bundler', '~> 1.12'
29
29
  spec.add_development_dependency 'pry', '~> 0.1'
data/lib/eth.rb CHANGED
@@ -30,15 +30,7 @@ module Eth
30
30
  end
31
31
 
32
32
  def v_base
33
- if chain_id
34
- (chain_id * 2) + 35
35
- else
36
- replayable_chain_id
37
- end
38
- end
39
-
40
- def prevent_replays?
41
- !chain_id.nil?
33
+ replayable_chain_id
42
34
  end
43
35
 
44
36
  def replayable_v?(v)
@@ -49,6 +41,12 @@ module Eth
49
41
  !!configuration.tx_data_hex
50
42
  end
51
43
 
44
+ def chain_id_from_signature(signature)
45
+ return nil if Eth.replayable_v?(signature[:v])
46
+
47
+ cid = (signature[:v] - 35) / 2
48
+ (cid < 1) ? nil : cid
49
+ end
52
50
 
53
51
  private
54
52
 
@@ -61,6 +59,7 @@ module Eth
61
59
  attr_accessor :chain_id, :tx_data_hex
62
60
 
63
61
  def initialize
62
+ self.chain_id = nil
64
63
  self.tx_data_hex = true
65
64
  end
66
65
  end
@@ -20,13 +20,19 @@ module Eth
20
20
 
21
21
  def self.decode(data)
22
22
  data = Utils.hex_to_bin(data) if data.match(/\A(?:0x)?\h+\Z/)
23
- deserialize(RLP.decode data)
23
+ txh = deserialize(RLP.decode data).to_h
24
+
25
+ txh[:chain_id] = Eth.chain_id_from_signature(txh)
26
+
27
+ self.new txh
24
28
  end
25
29
 
26
30
  def initialize(params)
27
31
  fields = {v: 0, r: 0, s: 0}.merge params
28
32
  fields[:to] = Utils.normalize_address(fields[:to])
29
33
 
34
+ self.chain_id = (params[:chain_id]) ? params.delete(:chain_id) : Eth.chain_id
35
+
30
36
  if params[:data]
31
37
  self.data = params.delete(:data)
32
38
  fields[:data_bin] = data_bin
@@ -37,7 +43,8 @@ module Eth
37
43
  end
38
44
 
39
45
  def unsigned_encoded
40
- RLP.encode(unsigned, sedes: sedes)
46
+ us = unsigned
47
+ RLP.encode(us, sedes: us.sedes)
41
48
  end
42
49
 
43
50
  def signing_data
@@ -53,12 +60,13 @@ module Eth
53
60
  end
54
61
 
55
62
  def sign(key)
56
- self.signature = key.sign(unsigned_encoded)
57
- vrs = Utils.v_r_s_for signature
58
- self.v = vrs[0]
63
+ sig = key.sign(unsigned_encoded)
64
+ vrs = Utils.v_r_s_for sig
65
+ self.v = (self.chain_id) ? ((self.chain_id * 2) + vrs[0] + 8) : vrs[0]
59
66
  self.r = vrs[1]
60
67
  self.s = vrs[2]
61
68
 
69
+ clear_signature
62
70
  self
63
71
  end
64
72
 
@@ -70,19 +78,28 @@ module Eth
70
78
  end
71
79
 
72
80
  def from
73
- if signature
74
- public_key = OpenSsl.recover_compact(signature_hash, signature)
81
+ if ecdsa_signature
82
+ public_key = OpenSsl.recover_compact(signature_hash, ecdsa_signature)
75
83
  Utils.public_key_to_address(public_key) if public_key
76
84
  end
77
85
  end
78
86
 
79
87
  def signature
80
88
  return @signature if @signature
81
- self.signature = [
82
- Utils.int_to_base256(v),
83
- Utils.zpad_int(r),
84
- Utils.zpad_int(s),
85
- ].join if [v, r, s].all?
89
+ @signature = { v: v, r: r, s: s } if [v, r, s].all? && (v > 0)
90
+ end
91
+
92
+ def ecdsa_signature
93
+ return @ecdsa_signature if @ecdsa_signature
94
+
95
+ if [v, r, s].all? && (v > 0)
96
+ s_v = (self.chain_id) ? (v - (self.chain_id * 2) - 8) : v
97
+ @ecdsa_signature = [
98
+ Utils.int_to_base256(s_v),
99
+ Utils.zpad_int(r),
100
+ Utils.zpad_int(s),
101
+ ].join
102
+ end
86
103
  end
87
104
 
88
105
  def hash
@@ -106,13 +123,37 @@ module Eth
106
123
  Eth.tx_data_hex? ? self.data_hex=(string) : self.data_bin=(string)
107
124
  end
108
125
 
126
+ def chain_id
127
+ @chain_id
128
+ end
129
+
130
+ def chain_id=(cid)
131
+ if cid != @chain_id
132
+ self.v = 0
133
+ self.r = 0
134
+ self.s = 0
135
+
136
+ clear_signature
137
+ end
138
+
139
+ @chain_id = (cid == 0) ? nil : cid
140
+ end
141
+
142
+ def prevent_replays?
143
+ !self.chain_id.nil?
144
+ end
109
145
 
110
146
  private
111
147
 
148
+ def clear_signature
149
+ @signature = nil
150
+ @ecdsa_signature = nil
151
+ end
152
+
112
153
  def hash_keys
113
154
  keys = self.class.serializable_fields.keys
114
155
  keys.delete(:data_bin)
115
- keys + [:data]
156
+ keys + [:data, :chain_id]
116
157
  end
117
158
 
118
159
  def check_transaction_validity
@@ -137,11 +178,13 @@ module Eth
137
178
  end
138
179
 
139
180
  def unsigned
140
- Tx.new to_h.merge(v: Eth.chain_id, r: 0, s: 0)
181
+ Tx.new to_h.merge(v: (self.chain_id) ? self.chain_id : 0, r: 0, s: 0)
141
182
  end
142
183
 
184
+ protected
185
+
143
186
  def sedes
144
- if Eth.prevent_replays? && !(Eth.replayable_v? v)
187
+ if self.prevent_replays? && !(Eth.replayable_v? v)
145
188
  self.class
146
189
  else
147
190
  UnsignedTx
@@ -1,3 +1,3 @@
1
1
  module Eth
2
- VERSION = "0.4.8"
2
+ VERSION = "0.4.10"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.8
4
+ version: 0.4.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Ellis
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-05 00:00:00.000000000 Z
11
+ date: 2018-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: digest-sha3
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 3.0.5
75
+ version: 3.0.6
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 3.0.5
82
+ version: 3.0.6
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: bundler
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -187,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
187
187
  version: '0'
188
188
  requirements: []
189
189
  rubyforge_project:
190
- rubygems_version: 2.5.2.1
190
+ rubygems_version: 2.7.6
191
191
  signing_key:
192
192
  specification_version: 4
193
193
  summary: Simple API to sign Ethereum transactions.