eth 0.4.6 → 0.4.8

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: 0c5f0d8fb53ed83ac74dbcb8d22159f0345adcec
4
- data.tar.gz: 6903709ca948490f7060ecef87dd1e213fda1c08
3
+ metadata.gz: 7e801e6af9201a0653adfca521abd33b5f2dab92
4
+ data.tar.gz: e0ed95cce6e8f25091ec6253e18654d539e64b2a
5
5
  SHA512:
6
- metadata.gz: b4558847999d40a3bde43a4704767bf66afc7a32d719c87f2ee75008879bd73d598225de09980bd0087143b415ef21bc76ed83fd41c192a6a0ba797ad4ac848a
7
- data.tar.gz: 111d01b2f8cf20d3a25bfcb9f098b1e643892dfe0d45a90c17d49a477ebca1259a13f775d3d22eaeeb8354aad6246ed5c543dae3b379bbb25fa6f6a42fdc435f
6
+ metadata.gz: c3cfeb4cb2d190095452908c1d40b341b808e10c03711c4a96e556b381dec18a6ac92c19f0021a35b85574fdadeb6d7c185226aff356f297788faef18dabbab3
7
+ data.tar.gz: f07015333af071a10c5a59a254293902ac9afe6e72ddcc27d782e69f97a19afcdad6e651bb80e7ad33a9033f50503568d9e865414108dcacb4117b8cdb37e241
@@ -4,6 +4,17 @@ 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
+ ## [0.4.8]
8
+
9
+ ### Added
10
+ - [@buhrmi](https://github.com/buhrmi) added Eth::Key#personal_sign.
11
+ - [@buhrmi](https://github.com/buhrmi) added Eth::Key#personal_recover.
12
+
13
+ ## [0.4.7]
14
+
15
+ ### Changed
16
+ - Updated MoneyTree dependency.
17
+
7
18
  ## [0.4.6]
8
19
 
9
20
  ### Added
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Eth [![Travis-CI](https://travis-ci.org/se3000/ruby-eth.svg?branch=master)](https://travis-ci.org/se3000/ruby-eth) [![Code Climate](https://codeclimate.com/github/se3000/ruby-eth/badges/gpa.svg)](https://codeclimate.com/github/se3000/ruby-eth) [![Gitter](https://badges.gitter.im/ruby-eth/Lobby.svg)](https://gitter.im/ruby-eth/Lobby)
2
2
 
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.
3
+ A simple library to build and sign Ethereum transactions. Allows separation of key and node management. Sign transactions and handle keys anywhere you can run ruby, broadcast transactions through any node.
4
4
 
5
5
  ## Installation
6
6
 
@@ -21,22 +21,30 @@ Or install it yourself as:
21
21
  ## Usage
22
22
 
23
23
  ### Keys
24
+
24
25
  Create a new public/private key and get its address:
26
+
25
27
  ```ruby
26
28
  key = Eth::Key.new
27
29
  key.private_hex
28
30
  key.public_hex
29
31
  key.address # EIP55 checksummed address
30
32
  ```
33
+
31
34
  Import an existing key:
35
+
32
36
  ```ruby
33
37
  old_key = Eth::Key.new priv: private_key
34
38
  ```
39
+
35
40
  Or decrypt an [encrypted key](https://github.com/ethereum/wiki/wiki/Web3-Secret-Storage-Definition):
41
+
36
42
  ```ruby
37
43
  decrypted_key = Eth::Key.decrypt File.read('./some/path.json'), 'p455w0rD'
38
44
  ```
45
+
39
46
  You can also encrypt your keys for use with other ethereum libraries:
47
+
40
48
  ```ruby
41
49
  encrypted_key_info = Eth::Key.encrypt key, 'p455w0rD'
42
50
  ```
@@ -44,6 +52,7 @@ encrypted_key_info = Eth::Key.encrypt key, 'p455w0rD'
44
52
  ### Transactions
45
53
 
46
54
  Build a transaction from scratch:
55
+
47
56
  ```ruby
48
57
  tx = Eth::Tx.new({
49
58
  data: hex_data,
@@ -54,31 +63,53 @@ tx = Eth::Tx.new({
54
63
  value: 1_000_000_000_000,
55
64
  })
56
65
  ```
66
+
57
67
  Or decode an encoded raw transaction:
68
+
58
69
  ```ruby
59
70
  tx = Eth::Tx.decode hex
60
71
  ```
61
72
 
62
73
  Then sign the transaction:
74
+
63
75
  ```ruby
64
76
  tx.sign key
65
77
  ```
78
+
66
79
  Get the raw transaction with `tx.hex`, and broadcast it through any Ethereum node. Or, just get the TXID with `tx.hash`.
67
80
 
68
81
  ### Utils
69
82
 
70
83
  Validate an [EIP55](https://github.com/ethereum/EIPs/issues/55) checksummed address:
84
+
71
85
  ```ruby
72
86
  Eth::Utils.valid_address? address
73
87
  ```
74
88
 
75
89
  Or add a checksum to an existing address:
90
+
76
91
  ```ruby
77
92
  Eth::Utils.format_address "0x4bc787699093f11316e819b5692be04a712c4e69" # => "0x4bc787699093f11316e819B5692be04A712C4E69"
78
93
  ```
79
94
 
95
+ ### Personal Signatures
96
+
97
+ You can recover public keys and generate web3/metamask-compatible signatures:
98
+
99
+ ```ruby
100
+ # Generate signature
101
+ key.personal_sign('hello world')
102
+
103
+ # Recover signature
104
+ message = 'test'
105
+ signature = '0x3eb24bd327df8c2b614c3f652ec86efe13aa721daf203820241c44861a26d37f2bffc6e03e68fc4c3d8d967054c9cb230ed34339b12ef89d512b42ae5bf8c2ae1c'
106
+ Eth::Key.personal_recover(message, signature) # => 043e5b33f0080491e21f9f5f7566de59a08faabf53edbc3c32aaacc438552b25fdde531f8d1053ced090e9879cbf2b0d1c054e4b25941dab9254d2070f39418afc
107
+ ```
108
+
80
109
  ### Configure
110
+
81
111
  In order to prevent replay attacks, you must specify which Ethereum chain your transactions are created for. See [EIP 155](https://github.com/ethereum/EIPs/issues/155) for more detail.
112
+
82
113
  ```ruby
83
114
  Eth.configure do |config|
84
115
  config.chain_id = 1 # nil by default, meaning valid on any chain
@@ -92,21 +123,23 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/se3000
92
123
  ### Tests
93
124
 
94
125
  First install the [Ethereum common tests](https://github.com/ethereum/tests):
126
+
95
127
  ```shell
96
128
  git submodule update --init
97
129
  ```
98
130
 
99
131
  Then run the associated tests:
132
+
100
133
  ```shell
101
134
  rspec
102
135
  ```
103
136
 
104
-
105
137
  ## License
106
138
 
107
139
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
108
140
 
109
141
  ## TODO
110
- - Better test suite.
111
- - Expose API for HD keys.
112
- - Support signing with [libsecp256k1](https://github.com/bitcoin-core/secp256k1).
142
+
143
+ * Better test suite.
144
+ * Expose API for HD keys.
145
+ * Support signing with [libsecp256k1](https://github.com/bitcoin-core/secp256k1).
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_dependency 'digest-sha3', '~> 1.1'
23
23
  spec.add_dependency 'ffi', '~> 1.0'
24
- spec.add_dependency 'money-tree', '~> 0.9'
24
+ spec.add_dependency 'money-tree', '~> 0.10.0'
25
25
  spec.add_dependency 'rlp', '~> 0.7.3'
26
26
  spec.add_dependency 'scrypt', '~> 3.0.5'
27
27
 
@@ -16,6 +16,10 @@ module Eth
16
16
  new priv: priv
17
17
  end
18
18
 
19
+ def self.personal_recover(message, signature)
20
+ bin_signature = Utils.hex_to_bin(signature).bytes.rotate(-1).pack('c*')
21
+ OpenSsl.recover_compact(Utils.keccak256(Utils.prefix_message(message)), bin_signature)
22
+ end
19
23
 
20
24
  def initialize(priv: nil)
21
25
  @private_key = MoneyTree::PrivateKey.new key: priv
@@ -55,6 +59,10 @@ module Eth
55
59
  public_hex == OpenSsl.recover_compact(hash, signature)
56
60
  end
57
61
 
62
+ def personal_sign(message)
63
+ Utils.bin_to_hex(sign(Utils.prefix_message(message)).bytes.rotate(1).pack('c*'))
64
+ end
65
+
58
66
 
59
67
  private
60
68
 
@@ -1,4 +1,5 @@
1
1
  require 'json'
2
+ require 'securerandom'
2
3
 
3
4
  class Eth::Key::Encrypter
4
5
  include Eth::Utils
@@ -51,6 +51,10 @@ module Eth
51
51
  prefix_hex bin_to_hex(binary)
52
52
  end
53
53
 
54
+ def prefix_message(message)
55
+ "\x19Ethereum Signed Message:\n#{message.length}#{message}"
56
+ end
57
+
54
58
  def public_key_to_address(hex)
55
59
  bytes = hex_to_bin(hex)
56
60
  address_bytes = Utils.keccak256(bytes[1..-1])[-20..-1]
@@ -86,7 +90,7 @@ module Eth
86
90
  end
87
91
 
88
92
  def zunpad(x)
89
- x.sub /\A\x00+/, ''
93
+ x.sub(/\A\x00+/, '')
90
94
  end
91
95
 
92
96
  def zpad_int(n, l=32)
@@ -1,3 +1,3 @@
1
1
  module Eth
2
- VERSION = "0.4.6"
2
+ VERSION = "0.4.8"
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.6
4
+ version: 0.4.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Ellis
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-12-17 00:00:00.000000000 Z
11
+ date: 2018-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: digest-sha3
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.9'
47
+ version: 0.10.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0.9'
54
+ version: 0.10.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rlp
57
57
  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.6.11
190
+ rubygems_version: 2.5.2.1
191
191
  signing_key:
192
192
  specification_version: 4
193
193
  summary: Simple API to sign Ethereum transactions.