eth 0.3.0 → 0.3.1
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.
- checksums.yaml +4 -4
- data/README.md +21 -16
- data/eth.gemspec +1 -2
- data/lib/eth.rb +0 -10
- data/lib/eth/key.rb +5 -2
- data/lib/eth/tx.rb +7 -6
- data/lib/eth/utils.rb +1 -4
- data/lib/eth/version.rb +1 -1
- metadata +5 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39ea19eb79ae52a313fb63ce5dd5f9df09dd6cd6
|
4
|
+
data.tar.gz: e418f5f13def9424252dfd8804f235fa94c395f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f2b7e85c649b70b6e7c99b37684e94ccf85543ce8d43e5ee871547aec67da7dba5716fb475402482864bc2240ae630eccca6804accbfb7468d5022d2d8ff240
|
7
|
+
data.tar.gz: 474ecae6e27db5623a1f7da63d4ab770660551582829ba35213e4b986d27bcb0238291ce2345175f6fb9779f088866b5c6a80101fe518b651ed57b1e22bb2a8a
|
data/README.md
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
#
|
1
|
+
# Eth
|
2
2
|
|
3
|
-
A simple
|
3
|
+
A simple library to build and sign Ethereum transactions. Allows separataion of key and node management. Sign transactions and handle keys anywhere you can run ruby, boradcast transactions through any node.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
gem '
|
10
|
+
gem 'eth'
|
11
11
|
```
|
12
12
|
|
13
13
|
And then execute:
|
@@ -16,38 +16,43 @@ And then execute:
|
|
16
16
|
|
17
17
|
Or install it yourself as:
|
18
18
|
|
19
|
-
$ gem install
|
19
|
+
$ gem install eth
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
23
|
### Keys
|
24
24
|
Create a new key:
|
25
|
-
```
|
26
|
-
key =
|
25
|
+
```ruby
|
26
|
+
key = Eth::Key.new
|
27
27
|
```
|
28
28
|
Or import and existing one:
|
29
|
-
```
|
30
|
-
old_key =
|
29
|
+
```ruby
|
30
|
+
old_key = Eth::Key.new priv: private_key
|
31
31
|
```
|
32
32
|
|
33
33
|
### Transactions
|
34
34
|
|
35
35
|
Build a transaction from scratch:
|
36
|
-
```
|
37
|
-
tx =
|
38
|
-
|
39
|
-
|
36
|
+
```ruby
|
37
|
+
tx = Eth::Tx.new({
|
38
|
+
data: 'abcdef',
|
39
|
+
gas_limit: 3_141_592,
|
40
|
+
gas_price: 20_000_000_000,
|
41
|
+
nonce: 0,
|
42
|
+
to: key.address,
|
43
|
+
value: 1_000_000_000_000,
|
44
|
+
})
|
40
45
|
```
|
41
46
|
Or decode an encoded raw transaction:
|
42
|
-
```
|
43
|
-
tx =
|
47
|
+
```ruby
|
48
|
+
tx = Eth::Tx.decode hex
|
44
49
|
```
|
45
50
|
|
46
51
|
Then sign the transaction:
|
47
|
-
```
|
52
|
+
```ruby
|
48
53
|
tx.sign key
|
49
54
|
```
|
50
|
-
|
55
|
+
Get the raw transaction with `tx.hex`, and broadcast it through any Ethereum node.
|
51
56
|
|
52
57
|
|
53
58
|
## Contributing
|
data/eth.gemspec
CHANGED
@@ -19,8 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.add_dependency "
|
23
|
-
spec.add_dependency "ethereum-base", "0.1.2"
|
22
|
+
spec.add_dependency "ethereum-base", "~> 0.1.4"
|
24
23
|
spec.add_dependency "ffi", "~> 1.0"
|
25
24
|
spec.add_dependency "money-tree", "~> 0.9"
|
26
25
|
spec.add_dependency "rlp", "~> 0.7"
|
data/lib/eth.rb
CHANGED
@@ -6,20 +6,10 @@ require 'rlp'
|
|
6
6
|
|
7
7
|
module Eth
|
8
8
|
|
9
|
-
BYTE_ZERO = "\x00".freeze
|
10
|
-
GTXCOST = 21000 # TX BASE GAS COST
|
11
|
-
GTXDATANONZERO = 68 # TX DATA NON ZERO BYTE GAS COST
|
12
|
-
GTXDATAZERO = 4 # TX DATA ZERO BYTE GAS COST
|
13
|
-
SECP256K1_N = 115792089237316195423570985008687907852837564279074904382605163141518161494337
|
14
|
-
UINT_MAX = 2**256 - 1
|
15
|
-
|
16
9
|
autoload :Key, 'eth/key'
|
17
10
|
autoload :OpenSsl, 'eth/open_ssl'
|
18
11
|
autoload :Sedes, 'eth/sedes'
|
19
12
|
autoload :Tx, 'eth/tx'
|
20
13
|
autoload :Utils, 'eth/utils'
|
21
14
|
|
22
|
-
class ValidationError < StandardError; end
|
23
|
-
class InvalidTransaction < ValidationError; end
|
24
|
-
|
25
15
|
end
|
data/lib/eth/key.rb
CHANGED
@@ -25,7 +25,10 @@ module Eth
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def sign(message)
|
28
|
-
|
28
|
+
sign_hash message_hash(message)
|
29
|
+
end
|
30
|
+
|
31
|
+
def sign_hash(hash)
|
29
32
|
loop do
|
30
33
|
signature = OpenSsl.sign_compact hash, private_hex, public_hex
|
31
34
|
return signature if valid_s? signature
|
@@ -46,7 +49,7 @@ module Eth
|
|
46
49
|
|
47
50
|
def valid_s?(signature)
|
48
51
|
s_value = Utils.v_r_s_for(signature).last
|
49
|
-
s_value <= SECP256K1_N/2 && s_value != 0
|
52
|
+
s_value <= Ethereum::Base::SECP256K1_N/2 && s_value != 0
|
50
53
|
end
|
51
54
|
|
52
55
|
end
|
data/lib/eth/tx.rb
CHANGED
@@ -74,10 +74,10 @@ module Eth
|
|
74
74
|
private
|
75
75
|
|
76
76
|
def check_transaction_validity
|
77
|
-
if [gas_price, gas_limit, value, nonce].max > UINT_MAX
|
78
|
-
raise InvalidTransaction, "Values way too high!"
|
77
|
+
if [gas_price, gas_limit, value, nonce].max > Ethereum::Base::UINT_MAX
|
78
|
+
raise Ethereum::Base::InvalidTransaction, "Values way too high!"
|
79
79
|
elsif gas_limit < intrinsic_gas_used
|
80
|
-
raise InvalidTransaction, "Gas limit too low"
|
80
|
+
raise Ethereum::Base::InvalidTransaction, "Gas limit too low"
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
@@ -88,11 +88,12 @@ module Eth
|
|
88
88
|
end
|
89
89
|
|
90
90
|
def intrinsic_gas_used
|
91
|
-
num_zero_bytes = data.count(BYTE_ZERO)
|
91
|
+
num_zero_bytes = data.count(Ethereum::Base::BYTE_ZERO)
|
92
92
|
num_non_zero_bytes = data.size - num_zero_bytes
|
93
93
|
|
94
|
-
GTXCOST +
|
95
|
-
|
94
|
+
Ethereum::Base::GTXCOST +
|
95
|
+
Ethereum::Base::GTXDATAZERO * num_zero_bytes +
|
96
|
+
Ethereum::Base::GTXDATANONZERO * num_non_zero_bytes
|
96
97
|
end
|
97
98
|
|
98
99
|
def signature_hash
|
data/lib/eth/utils.rb
CHANGED
data/lib/eth/version.rb
CHANGED
metadata
CHANGED
@@ -1,43 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Ellis
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: ethereum-base
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.1.4
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: ethereum-base
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - '='
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 0.1.2
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - '='
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 0.1.2
|
26
|
+
version: 0.1.4
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: ffi
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -185,4 +171,3 @@ signing_key:
|
|
185
171
|
specification_version: 4
|
186
172
|
summary: Simple API to sign Ethereum transactions.
|
187
173
|
test_files: []
|
188
|
-
has_rdoc:
|