eth 0.3.0 → 0.3.1

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
2
  SHA1:
3
- metadata.gz: 1e66df112e63648f3f2d9c0aaeda96f69d0d080e
4
- data.tar.gz: 592b07bd1c4de2d7d0ca45fcdd9af89dcd016352
3
+ metadata.gz: 39ea19eb79ae52a313fb63ce5dd5f9df09dd6cd6
4
+ data.tar.gz: e418f5f13def9424252dfd8804f235fa94c395f0
5
5
  SHA512:
6
- metadata.gz: 79b7fde0612955430559fdb38087ebd04bb9eab172250ea90a20d00e927b8b3ade6b1f34c8dff979564a72db5f2532ec96e427ba6e9c116d0d7c6d9e6ee9ee4e
7
- data.tar.gz: ba31aabf2af13fb361eaeae8c145954f8a7fe45587ca823ab8fafb3ea9779fd05b2ab7defdc847cd1960c028d4f97115f04b01f3111ea749bc0925df47706778
6
+ metadata.gz: 2f2b7e85c649b70b6e7c99b37684e94ccf85543ce8d43e5ee871547aec67da7dba5716fb475402482864bc2240ae630eccca6804accbfb7468d5022d2d8ff240
7
+ data.tar.gz: 474ecae6e27db5623a1f7da63d4ab770660551582829ba35213e4b986d27bcb0238291ce2345175f6fb9779f088866b5c6a80101fe518b651ed57b1e22bb2a8a
data/README.md CHANGED
@@ -1,13 +1,13 @@
1
- # Ethereum::Tx
1
+ # Eth
2
2
 
3
- A simple, light weight, library to build and sign Ethereum transactions.
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 'ethereum-tx'
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 ethereum-tx
19
+ $ gem install eth
20
20
 
21
21
  ## Usage
22
22
 
23
23
  ### Keys
24
24
  Create a new key:
25
- ```
26
- key = Ethereum::Key.new
25
+ ```ruby
26
+ key = Eth::Key.new
27
27
  ```
28
28
  Or import and existing one:
29
- ```
30
- old_key = Ethereum::Key.new private_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 = Ethereum::Tx.new to: key.address, gas_price: 25_000, gas_limit: 25_000
38
- tx.data = 'abcdef' #optional
39
- tx.value = 1_000_000_000_000 #optional
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 = Ethereum::Tx.decode hex
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
- Finally you can broadcast the raw transaction, `tx.encoded`, to your Ethereum node.
55
+ Get the raw transaction with `tx.hex`, and broadcast it through any Ethereum node.
51
56
 
52
57
 
53
58
  ## Contributing
@@ -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 "digest-sha3", "~> 1.1"
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
@@ -25,7 +25,10 @@ module Eth
25
25
  end
26
26
 
27
27
  def sign(message)
28
- hash = message_hash(message)
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
@@ -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 + GTXDATAZERO * num_zero_bytes +
95
- GTXDATANONZERO * num_non_zero_bytes
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
@@ -2,12 +2,9 @@ module Eth
2
2
 
3
3
  module Utils
4
4
 
5
+ extend Ethereum::Base::Utils
5
6
  extend self
6
7
 
7
- def keccak256(message)
8
- Digest::SHA3.new(256).digest(message)
9
- end
10
-
11
8
  def normalize_address(address)
12
9
  if address.nil? || address == ''
13
10
  ''
@@ -1,3 +1,3 @@
1
1
  module Eth
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
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.0
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-07-17 00:00:00.000000000 Z
11
+ date: 2016-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: digest-sha3
14
+ name: ethereum-base
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.1'
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: '1.1'
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: