eth 0.4.8 → 0.4.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/build.yml +26 -0
- data/.github/workflows/codeql.yml +38 -0
- data/.gitignore +40 -7
- data/CHANGELOG.md +35 -9
- data/Gemfile +3 -1
- data/LICENSE.txt +2 -1
- data/README.md +10 -4
- data/eth.gemspec +27 -13
- data/lib/eth/open_ssl.rb +75 -8
- data/lib/eth/tx.rb +58 -15
- data/lib/eth/version.rb +1 -1
- data/lib/eth.rb +8 -9
- metadata +38 -29
- data/.travis.yml +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 87e846748f62ce3874417ba24d249c9eaf81a53de040c40d846d60ff0be0e1b3
|
4
|
+
data.tar.gz: 8a7508a79ebef3100dfca6b9be67ca26c1d132a4eaaacc96f599afe58a57db02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b1039dcd261b7e8d756e7f05eb9ce25f239c6d83c3fbd924e6e9675246b3d373b70748f47114d30f412281ed17e9f6c31d7462669119ac8ef8305a7becdd0be
|
7
|
+
data.tar.gz: f07f7863b9af5c74d461e430da54f8822252451c60bfeff7499085b28209e707ddce3ae0e44bc60ef9b73db5d60d7cf20409b9f4d3e928f6bb0def2438ea0323
|
@@ -0,0 +1,26 @@
|
|
1
|
+
---
|
2
|
+
name: Build
|
3
|
+
|
4
|
+
on:
|
5
|
+
pull_request:
|
6
|
+
branches:
|
7
|
+
- develop
|
8
|
+
push:
|
9
|
+
branches:
|
10
|
+
- develop
|
11
|
+
|
12
|
+
jobs:
|
13
|
+
build:
|
14
|
+
runs-on: ubuntu-latest
|
15
|
+
steps:
|
16
|
+
- uses: actions/checkout@v2
|
17
|
+
- uses: ruby/setup-ruby@v1
|
18
|
+
with:
|
19
|
+
ruby-version: 3.0
|
20
|
+
- name: Install Dependencies
|
21
|
+
run: |
|
22
|
+
git submodule update --init
|
23
|
+
bundle install
|
24
|
+
- name: Run Tests
|
25
|
+
run: |
|
26
|
+
rspec
|
@@ -0,0 +1,38 @@
|
|
1
|
+
---
|
2
|
+
name: CodeQL
|
3
|
+
|
4
|
+
on:
|
5
|
+
pull_request:
|
6
|
+
branches:
|
7
|
+
- develop
|
8
|
+
push:
|
9
|
+
branches:
|
10
|
+
- develop
|
11
|
+
schedule:
|
12
|
+
-
|
13
|
+
cron: "45 1 * * 3"
|
14
|
+
|
15
|
+
jobs:
|
16
|
+
analyze:
|
17
|
+
name: Analyze
|
18
|
+
runs-on: ubuntu-latest
|
19
|
+
permissions:
|
20
|
+
actions: read
|
21
|
+
contents: read
|
22
|
+
security-events: write
|
23
|
+
strategy:
|
24
|
+
fail-fast: false
|
25
|
+
matrix:
|
26
|
+
language:
|
27
|
+
- ruby
|
28
|
+
steps:
|
29
|
+
- name: "Checkout repository"
|
30
|
+
uses: actions/checkout@v2
|
31
|
+
- name: "Initialize CodeQL"
|
32
|
+
uses: github/codeql-action/init@v1
|
33
|
+
with:
|
34
|
+
languages: "${{ matrix.language }}"
|
35
|
+
- name: Autobuild
|
36
|
+
uses: github/codeql-action/autobuild@v1
|
37
|
+
- name: "Perform CodeQL Analysis"
|
38
|
+
uses: github/codeql-action/analyze@v1
|
data/.gitignore
CHANGED
@@ -1,10 +1,43 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
/
|
4
|
-
/
|
1
|
+
*.DS_Store
|
2
|
+
|
3
|
+
/test/test_vectors.rb
|
4
|
+
/ext/digest/Makefile
|
5
|
+
/ext/digest/keccak.so
|
6
|
+
/ext/digest/mkmf.log
|
7
|
+
|
8
|
+
*.o
|
9
|
+
*.so
|
10
|
+
*.gem
|
11
|
+
*.log
|
12
|
+
*.rbc
|
13
|
+
/.config
|
14
|
+
/.rake_tasks~
|
5
15
|
/coverage/
|
6
|
-
/
|
16
|
+
/InstalledFiles
|
7
17
|
/pkg/
|
8
|
-
/spec/reports/
|
9
18
|
/tmp/
|
10
|
-
|
19
|
+
|
20
|
+
# RSpec configuration and generated files:
|
21
|
+
/.rspec
|
22
|
+
/spec/examples.txt
|
23
|
+
|
24
|
+
# Documentation cache and generated files:
|
25
|
+
/.yardoc/
|
26
|
+
/_yardoc/
|
27
|
+
/doc/
|
28
|
+
/rdoc/
|
29
|
+
|
30
|
+
# Environment normalization:
|
31
|
+
/.bundle/
|
32
|
+
/vendor/bundle/*
|
33
|
+
!/vendor/bundle/.keep
|
34
|
+
/lib/bundler/man/
|
35
|
+
|
36
|
+
# For a library or gem, you might want to ignore these files since the code is
|
37
|
+
# intended to run in multiple environments; otherwise, check them in:
|
38
|
+
/Gemfile.lock
|
39
|
+
/.ruby-version
|
40
|
+
/.ruby-gemset
|
41
|
+
|
42
|
+
# Unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
43
|
+
.rvmrc
|
data/CHANGELOG.md
CHANGED
@@ -4,34 +4,63 @@ 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
|
-
|
7
|
+
### Unreleased
|
8
|
+
|
9
|
+
## [0.4.16]
|
10
|
+
### Changed
|
11
|
+
- Docs: update changelog [#65](https://github.com/se3000/ruby-eth/pull/65)
|
12
|
+
- Gems: bump version to 0.4.16 [#65](https://github.com/se3000/ruby-eth/pull/65)
|
13
|
+
- License: update copyright notice [#64](https://github.com/se3000/ruby-eth/pull/64)
|
14
|
+
- Docs: add badges to readme [#64](https://github.com/se3000/ruby-eth/pull/64)
|
15
|
+
- Git: deprecating master [#63](https://github.com/se3000/ruby-eth/pull/63)
|
16
|
+
- CI: replace travis with github actions [#62](https://github.com/se3000/ruby-eth/pull/62)
|
17
|
+
- Gems: replace digest-sha3-patched with keccak [#58](https://github.com/se3000/ruby-eth/pull/58)
|
18
|
+
|
19
|
+
## [0.4.13], [0.4.14], [0.4.15]
|
20
|
+
_Released as [`eth-patched`](https://github.com/q9f/ruby-eth) from a different source tree._
|
21
|
+
|
22
|
+
## [0.4.12]
|
23
|
+
### Changed
|
24
|
+
- Bump rake version because of security vulnerability
|
8
25
|
|
26
|
+
## [0.4.11]
|
27
|
+
### Added
|
28
|
+
- Support for recovering signatures with a V value below 27 (like from Ledger hardware wallets)
|
29
|
+
|
30
|
+
## [0.4.10]
|
31
|
+
### Changed
|
32
|
+
- Use updated sha3 dependency
|
33
|
+
- Improved OpenSSL support
|
34
|
+
|
35
|
+
### Changed
|
36
|
+
- Changed Eth::Configuration.default_chain_id back to .chain_id for dependent libraries.
|
37
|
+
|
38
|
+
## [0.4.9]
|
39
|
+
### Changed
|
40
|
+
- [escoffon](https://github.com/escoffon) added support for chain IDs larger than 120.
|
41
|
+
|
42
|
+
## [0.4.8]
|
9
43
|
### Added
|
10
44
|
- [@buhrmi](https://github.com/buhrmi) added Eth::Key#personal_sign.
|
11
45
|
- [@buhrmi](https://github.com/buhrmi) added Eth::Key#personal_recover.
|
12
46
|
|
13
47
|
## [0.4.7]
|
14
|
-
|
15
48
|
### Changed
|
16
49
|
- Updated MoneyTree dependency.
|
17
50
|
|
18
51
|
## [0.4.6]
|
19
|
-
|
20
52
|
### Added
|
21
53
|
- Support scrypt private key decryption
|
22
54
|
|
23
55
|
## [0.4.5]
|
24
|
-
|
25
56
|
### Changed
|
26
57
|
- Further improve Open SSL configurability
|
27
58
|
|
28
59
|
## [0.4.4]
|
29
|
-
|
30
60
|
### Changed
|
31
61
|
- Support old versions of SSL to help avoid preious breaking changes
|
32
62
|
|
33
63
|
## [0.4.3]
|
34
|
-
|
35
64
|
### Added
|
36
65
|
- Eth::Key::Encrypter class to handle encrypting keys.
|
37
66
|
- Eth::Key.encrypt as a nice wrapper around Encrypter class.
|
@@ -39,7 +68,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
39
68
|
- Eth::Key.decrypt as a nice wrapper around Decrypter class.
|
40
69
|
|
41
70
|
## [0.4.2]
|
42
|
-
|
43
71
|
### Added
|
44
72
|
- Address#valid? to validate EIP55 checksums.
|
45
73
|
- Address#checksummed to generate EIP55 checksums.
|
@@ -51,12 +79,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
51
79
|
|
52
80
|
|
53
81
|
## [0.4.1]
|
54
|
-
|
55
82
|
### Changed
|
56
83
|
- Tx#hash includes the '0x' hex prefix.
|
57
84
|
|
58
85
|
## [0.4.0]
|
59
|
-
|
60
86
|
### Added
|
61
87
|
- Tx#data_bin returns the data field of a transaction in binary.
|
62
88
|
- Tx#data_hex returns the data field of a transaction as a hexadecimal string.
|
data/Gemfile
CHANGED
data/LICENSE.txt
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
The MIT License (MIT)
|
2
2
|
|
3
|
-
Copyright (c) 2016 Steve Ellis
|
3
|
+
Copyright (c) 2016-2021 Steve Ellis
|
4
|
+
Copyright (c) 2021-2022 Afri Schoedon
|
4
5
|
|
5
6
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
7
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.md
CHANGED
@@ -1,4 +1,10 @@
|
|
1
|
-
# Eth
|
1
|
+
# Eth for Ruby
|
2
|
+
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/se3000/ruby-eth/Build)](https://github.com/se3000/ruby-eth/actions)
|
3
|
+
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/se3000/ruby-eth)](https://github.com/se3000/ruby-eth/releases)
|
4
|
+
[![Gem](https://img.shields.io/gem/v/eth)](https://rubygems.org/gems/eth)
|
5
|
+
[![Gem](https://img.shields.io/gem/dt/eth)](https://rubygems.org/gems/eth)
|
6
|
+
[![GitHub top language](https://img.shields.io/github/languages/top/se3000/ruby-eth?color=red)](https://github.com/se3000/ruby-eth/pulse)
|
7
|
+
[![GitHub](https://img.shields.io/github/license/se3000/ruby-eth)](LICENSE)
|
2
8
|
|
3
9
|
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
10
|
|
@@ -12,7 +18,7 @@ gem 'eth'
|
|
12
18
|
|
13
19
|
And then execute:
|
14
20
|
|
15
|
-
$ bundle
|
21
|
+
$ bundle install
|
16
22
|
|
17
23
|
Or install it yourself as:
|
18
24
|
|
@@ -118,7 +124,7 @@ end
|
|
118
124
|
|
119
125
|
## Contributing
|
120
126
|
|
121
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/se3000/
|
127
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/se3000/ruby-eth. Tests are encouraged.
|
122
128
|
|
123
129
|
### Tests
|
124
130
|
|
@@ -136,7 +142,7 @@ rspec
|
|
136
142
|
|
137
143
|
## License
|
138
144
|
|
139
|
-
The gem is available as open
|
145
|
+
The gem is available as open-source software under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
140
146
|
|
141
147
|
## TODO
|
142
148
|
|
data/eth.gemspec
CHANGED
@@ -1,32 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# coding: utf-8
|
2
|
-
|
3
|
-
|
3
|
+
|
4
|
+
lib = File.expand_path('lib', __dir__).freeze
|
5
|
+
$LOAD_PATH.unshift lib unless $LOAD_PATH.include? lib
|
6
|
+
|
4
7
|
require 'eth/version'
|
5
8
|
|
6
9
|
Gem::Specification.new do |spec|
|
7
10
|
spec.name = "eth"
|
8
11
|
spec.version = Eth::VERSION
|
9
|
-
spec.authors = ["Steve Ellis"]
|
10
|
-
spec.email = ["email@steveell.is"]
|
12
|
+
spec.authors = ["Steve Ellis", "Afri Schoedon"]
|
13
|
+
spec.email = ["email@steveell.is", "ruby@q9f.cc"]
|
11
14
|
|
12
15
|
spec.summary = %q{Simple API to sign Ethereum transactions.}
|
13
16
|
spec.description = %q{Library to build, parse, and sign Ethereum transactions.}
|
14
17
|
spec.homepage = "https://github.com/se3000/ruby-eth"
|
15
18
|
spec.license = "MIT"
|
16
19
|
|
20
|
+
spec.metadata = {
|
21
|
+
'homepage_uri' => 'https://github.com/se3000/ruby-eth',
|
22
|
+
'source_code_uri' => 'https://github.com/se3000/ruby-eth',
|
23
|
+
'github_repo' => 'https://github.com/se3000/ruby-eth',
|
24
|
+
'bug_tracker_uri' => 'https://github.com/se3000/ruby-eth/issues',
|
25
|
+
}.freeze
|
26
|
+
|
17
27
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
28
|
spec.bindir = "exe"
|
19
29
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
30
|
spec.require_paths = ["lib"]
|
31
|
+
spec.test_files = spec.files.grep %r{^(test|spec|features)/}
|
32
|
+
|
33
|
+
spec.add_dependency 'keccak', '~> 1.2'
|
34
|
+
spec.add_dependency 'ffi', '~> 1.15'
|
35
|
+
spec.add_dependency 'money-tree', '~> 0.10'
|
36
|
+
spec.add_dependency 'rlp', '~> 0.7'
|
37
|
+
spec.add_dependency 'scrypt', '~> 3.0'
|
21
38
|
|
22
|
-
spec.
|
23
|
-
spec.
|
24
|
-
spec.add_dependency 'money-tree', '~> 0.10.0'
|
25
|
-
spec.add_dependency 'rlp', '~> 0.7.3'
|
26
|
-
spec.add_dependency 'scrypt', '~> 3.0.5'
|
39
|
+
spec.platform = Gem::Platform::RUBY
|
40
|
+
spec.required_ruby_version = ">= 2.2", "< 4.0"
|
27
41
|
|
28
|
-
spec.add_development_dependency 'bundler', '~>
|
29
|
-
spec.add_development_dependency 'pry', '~> 0.
|
30
|
-
spec.add_development_dependency 'rake', '~>
|
31
|
-
spec.add_development_dependency 'rspec', '~> 3.
|
42
|
+
spec.add_development_dependency 'bundler', '~> 2.2'
|
43
|
+
spec.add_development_dependency 'pry', '~> 0.14'
|
44
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
45
|
+
spec.add_development_dependency 'rspec', '~> 3.10'
|
32
46
|
end
|
data/lib/eth/open_ssl.rb
CHANGED
@@ -8,18 +8,69 @@ module Eth
|
|
8
8
|
if FFI::Platform.windows?
|
9
9
|
ffi_lib 'libeay32', 'ssleay32'
|
10
10
|
else
|
11
|
-
ffi_lib [
|
11
|
+
ffi_lib [
|
12
|
+
'libssl.so.1.1.0', 'libssl.so.1.1',
|
13
|
+
'libssl.so.1.0.0', 'libssl.so.10',
|
14
|
+
'ssl'
|
15
|
+
]
|
12
16
|
end
|
13
17
|
|
14
18
|
NID_secp256k1 = 714
|
15
19
|
POINT_CONVERSION_COMPRESSED = 2
|
16
20
|
POINT_CONVERSION_UNCOMPRESSED = 4
|
17
21
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
+
# OpenSSL 1.1.0 version as a numerical version value as defined in:
|
23
|
+
# https://www.openssl.org/docs/man1.1.0/man3/OpenSSL_version.html
|
24
|
+
VERSION_1_1_0_NUM = 0x10100000
|
25
|
+
|
26
|
+
# OpenSSL 1.1.0 engine constants, taken from:
|
27
|
+
# https://github.com/openssl/openssl/blob/2be8c56a39b0ec2ec5af6ceaf729df154d784a43/include/openssl/crypto.h
|
28
|
+
OPENSSL_INIT_ENGINE_RDRAND = 0x00000200
|
29
|
+
OPENSSL_INIT_ENGINE_DYNAMIC = 0x00000400
|
30
|
+
OPENSSL_INIT_ENGINE_CRYPTODEV = 0x00001000
|
31
|
+
OPENSSL_INIT_ENGINE_CAPI = 0x00002000
|
32
|
+
OPENSSL_INIT_ENGINE_PADLOCK = 0x00004000
|
33
|
+
OPENSSL_INIT_ENGINE_ALL_BUILTIN = (
|
34
|
+
OPENSSL_INIT_ENGINE_RDRAND |
|
35
|
+
OPENSSL_INIT_ENGINE_DYNAMIC |
|
36
|
+
OPENSSL_INIT_ENGINE_CRYPTODEV |
|
37
|
+
OPENSSL_INIT_ENGINE_CAPI |
|
38
|
+
OPENSSL_INIT_ENGINE_PADLOCK
|
39
|
+
)
|
40
|
+
|
41
|
+
# OpenSSL 1.1.0 load strings constant, taken from:
|
42
|
+
# https://github.com/openssl/openssl/blob/c162c126be342b8cd97996346598ecf7db56130f/include/openssl/ssl.h
|
43
|
+
OPENSSL_INIT_LOAD_SSL_STRINGS = 0x00200000
|
44
|
+
|
45
|
+
# This is the very first function we need to use to determine what version
|
46
|
+
# of OpenSSL we are interacting with.
|
47
|
+
begin
|
48
|
+
attach_function :OpenSSL_version_num, [], :ulong
|
49
|
+
rescue FFI::NotFoundError
|
50
|
+
attach_function :SSLeay, [], :long
|
51
|
+
end
|
52
|
+
|
53
|
+
# Returns the version of SSL present.
|
54
|
+
#
|
55
|
+
# @return [Integer] version number as an integer.
|
56
|
+
def self.version
|
57
|
+
if self.respond_to?(:OpenSSL_version_num)
|
58
|
+
OpenSSL_version_num()
|
59
|
+
else
|
60
|
+
SSLeay()
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
if version >= VERSION_1_1_0_NUM
|
65
|
+
# Initialization procedure for the library was changed in OpenSSL 1.1.0
|
66
|
+
attach_function :OPENSSL_init_ssl, [:uint64, :pointer], :int
|
67
|
+
else
|
68
|
+
attach_function :SSL_library_init, [], :int
|
69
|
+
attach_function :ERR_load_crypto_strings, [], :void
|
70
|
+
attach_function :SSL_load_error_strings, [], :void
|
71
|
+
end
|
22
72
|
|
73
|
+
attach_function :RAND_poll, [], :int
|
23
74
|
attach_function :BN_CTX_free, [:pointer], :int
|
24
75
|
attach_function :BN_CTX_new, [], :pointer
|
25
76
|
attach_function :BN_add, [:pointer, :pointer, :pointer], :int
|
@@ -157,7 +208,15 @@ module Eth
|
|
157
208
|
return false if signature.bytesize != 65
|
158
209
|
|
159
210
|
version = signature.unpack('C')[0]
|
211
|
+
|
212
|
+
# Version of signature should be 27 or 28, but 0 and 1 are also possible versions
|
213
|
+
# which can show up in Ledger hardwallet signings
|
214
|
+
if version < 27
|
215
|
+
version += 27
|
216
|
+
end
|
217
|
+
|
160
218
|
v_base = Eth.replayable_v?(version) ? Eth.replayable_chain_id : Eth.v_base
|
219
|
+
|
161
220
|
return false if version < v_base
|
162
221
|
|
163
222
|
recover_public_key_from_signature(hash, signature, (version - v_base), false)
|
@@ -165,9 +224,17 @@ module Eth
|
|
165
224
|
|
166
225
|
def init_ffi_ssl
|
167
226
|
return if @ssl_loaded
|
168
|
-
|
169
|
-
|
170
|
-
|
227
|
+
if version >= VERSION_1_1_0_NUM
|
228
|
+
OPENSSL_init_ssl(
|
229
|
+
OPENSSL_INIT_LOAD_SSL_STRINGS | OPENSSL_INIT_ENGINE_ALL_BUILTIN,
|
230
|
+
nil
|
231
|
+
)
|
232
|
+
else
|
233
|
+
SSL_library_init()
|
234
|
+
ERR_load_crypto_strings()
|
235
|
+
SSL_load_error_strings()
|
236
|
+
end
|
237
|
+
|
171
238
|
RAND_poll()
|
172
239
|
@ssl_loaded = true
|
173
240
|
end
|
data/lib/eth/tx.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
57
|
-
vrs = Utils.v_r_s_for
|
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
|
74
|
-
public_key = OpenSsl.recover_compact(signature_hash,
|
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
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
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:
|
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
|
187
|
+
if self.prevent_replays? && !(Eth.replayable_v? v)
|
145
188
|
self.class
|
146
189
|
else
|
147
190
|
UnsignedTx
|
data/lib/eth/version.rb
CHANGED
data/lib/eth.rb
CHANGED
@@ -30,15 +30,7 @@ module Eth
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def v_base
|
33
|
-
|
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
|
metadata
CHANGED
@@ -1,152 +1,155 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Ellis
|
8
|
-
|
8
|
+
- Afri Schoedon
|
9
|
+
autorequire:
|
9
10
|
bindir: exe
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2021-10-30 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
15
|
+
name: keccak
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
16
17
|
requirements:
|
17
18
|
- - "~>"
|
18
19
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
20
|
+
version: '1.2'
|
20
21
|
type: :runtime
|
21
22
|
prerelease: false
|
22
23
|
version_requirements: !ruby/object:Gem::Requirement
|
23
24
|
requirements:
|
24
25
|
- - "~>"
|
25
26
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
27
|
+
version: '1.2'
|
27
28
|
- !ruby/object:Gem::Dependency
|
28
29
|
name: ffi
|
29
30
|
requirement: !ruby/object:Gem::Requirement
|
30
31
|
requirements:
|
31
32
|
- - "~>"
|
32
33
|
- !ruby/object:Gem::Version
|
33
|
-
version: '1.
|
34
|
+
version: '1.15'
|
34
35
|
type: :runtime
|
35
36
|
prerelease: false
|
36
37
|
version_requirements: !ruby/object:Gem::Requirement
|
37
38
|
requirements:
|
38
39
|
- - "~>"
|
39
40
|
- !ruby/object:Gem::Version
|
40
|
-
version: '1.
|
41
|
+
version: '1.15'
|
41
42
|
- !ruby/object:Gem::Dependency
|
42
43
|
name: money-tree
|
43
44
|
requirement: !ruby/object:Gem::Requirement
|
44
45
|
requirements:
|
45
46
|
- - "~>"
|
46
47
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.10
|
48
|
+
version: '0.10'
|
48
49
|
type: :runtime
|
49
50
|
prerelease: false
|
50
51
|
version_requirements: !ruby/object:Gem::Requirement
|
51
52
|
requirements:
|
52
53
|
- - "~>"
|
53
54
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.10
|
55
|
+
version: '0.10'
|
55
56
|
- !ruby/object:Gem::Dependency
|
56
57
|
name: rlp
|
57
58
|
requirement: !ruby/object:Gem::Requirement
|
58
59
|
requirements:
|
59
60
|
- - "~>"
|
60
61
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.7
|
62
|
+
version: '0.7'
|
62
63
|
type: :runtime
|
63
64
|
prerelease: false
|
64
65
|
version_requirements: !ruby/object:Gem::Requirement
|
65
66
|
requirements:
|
66
67
|
- - "~>"
|
67
68
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.7
|
69
|
+
version: '0.7'
|
69
70
|
- !ruby/object:Gem::Dependency
|
70
71
|
name: scrypt
|
71
72
|
requirement: !ruby/object:Gem::Requirement
|
72
73
|
requirements:
|
73
74
|
- - "~>"
|
74
75
|
- !ruby/object:Gem::Version
|
75
|
-
version: 3.0
|
76
|
+
version: '3.0'
|
76
77
|
type: :runtime
|
77
78
|
prerelease: false
|
78
79
|
version_requirements: !ruby/object:Gem::Requirement
|
79
80
|
requirements:
|
80
81
|
- - "~>"
|
81
82
|
- !ruby/object:Gem::Version
|
82
|
-
version: 3.0
|
83
|
+
version: '3.0'
|
83
84
|
- !ruby/object:Gem::Dependency
|
84
85
|
name: bundler
|
85
86
|
requirement: !ruby/object:Gem::Requirement
|
86
87
|
requirements:
|
87
88
|
- - "~>"
|
88
89
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
90
|
+
version: '2.2'
|
90
91
|
type: :development
|
91
92
|
prerelease: false
|
92
93
|
version_requirements: !ruby/object:Gem::Requirement
|
93
94
|
requirements:
|
94
95
|
- - "~>"
|
95
96
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
97
|
+
version: '2.2'
|
97
98
|
- !ruby/object:Gem::Dependency
|
98
99
|
name: pry
|
99
100
|
requirement: !ruby/object:Gem::Requirement
|
100
101
|
requirements:
|
101
102
|
- - "~>"
|
102
103
|
- !ruby/object:Gem::Version
|
103
|
-
version: '0.
|
104
|
+
version: '0.14'
|
104
105
|
type: :development
|
105
106
|
prerelease: false
|
106
107
|
version_requirements: !ruby/object:Gem::Requirement
|
107
108
|
requirements:
|
108
109
|
- - "~>"
|
109
110
|
- !ruby/object:Gem::Version
|
110
|
-
version: '0.
|
111
|
+
version: '0.14'
|
111
112
|
- !ruby/object:Gem::Dependency
|
112
113
|
name: rake
|
113
114
|
requirement: !ruby/object:Gem::Requirement
|
114
115
|
requirements:
|
115
116
|
- - "~>"
|
116
117
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
118
|
+
version: '13.0'
|
118
119
|
type: :development
|
119
120
|
prerelease: false
|
120
121
|
version_requirements: !ruby/object:Gem::Requirement
|
121
122
|
requirements:
|
122
123
|
- - "~>"
|
123
124
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
125
|
+
version: '13.0'
|
125
126
|
- !ruby/object:Gem::Dependency
|
126
127
|
name: rspec
|
127
128
|
requirement: !ruby/object:Gem::Requirement
|
128
129
|
requirements:
|
129
130
|
- - "~>"
|
130
131
|
- !ruby/object:Gem::Version
|
131
|
-
version: '3.
|
132
|
+
version: '3.10'
|
132
133
|
type: :development
|
133
134
|
prerelease: false
|
134
135
|
version_requirements: !ruby/object:Gem::Requirement
|
135
136
|
requirements:
|
136
137
|
- - "~>"
|
137
138
|
- !ruby/object:Gem::Version
|
138
|
-
version: '3.
|
139
|
+
version: '3.10'
|
139
140
|
description: Library to build, parse, and sign Ethereum transactions.
|
140
141
|
email:
|
141
142
|
- email@steveell.is
|
143
|
+
- ruby@q9f.cc
|
142
144
|
executables: []
|
143
145
|
extensions: []
|
144
146
|
extra_rdoc_files: []
|
145
147
|
files:
|
148
|
+
- ".github/workflows/build.yml"
|
149
|
+
- ".github/workflows/codeql.yml"
|
146
150
|
- ".gitignore"
|
147
151
|
- ".gitmodules"
|
148
152
|
- ".rspec"
|
149
|
-
- ".travis.yml"
|
150
153
|
- CHANGELOG.md
|
151
154
|
- Gemfile
|
152
155
|
- LICENSE.txt
|
@@ -170,8 +173,12 @@ files:
|
|
170
173
|
homepage: https://github.com/se3000/ruby-eth
|
171
174
|
licenses:
|
172
175
|
- MIT
|
173
|
-
metadata:
|
174
|
-
|
176
|
+
metadata:
|
177
|
+
homepage_uri: https://github.com/se3000/ruby-eth
|
178
|
+
source_code_uri: https://github.com/se3000/ruby-eth
|
179
|
+
github_repo: https://github.com/se3000/ruby-eth
|
180
|
+
bug_tracker_uri: https://github.com/se3000/ruby-eth/issues
|
181
|
+
post_install_message:
|
175
182
|
rdoc_options: []
|
176
183
|
require_paths:
|
177
184
|
- lib
|
@@ -179,16 +186,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
179
186
|
requirements:
|
180
187
|
- - ">="
|
181
188
|
- !ruby/object:Gem::Version
|
182
|
-
version: '
|
189
|
+
version: '2.2'
|
190
|
+
- - "<"
|
191
|
+
- !ruby/object:Gem::Version
|
192
|
+
version: '4.0'
|
183
193
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
184
194
|
requirements:
|
185
195
|
- - ">="
|
186
196
|
- !ruby/object:Gem::Version
|
187
197
|
version: '0'
|
188
198
|
requirements: []
|
189
|
-
|
190
|
-
|
191
|
-
signing_key:
|
199
|
+
rubygems_version: 3.2.29
|
200
|
+
signing_key:
|
192
201
|
specification_version: 4
|
193
202
|
summary: Simple API to sign Ethereum transactions.
|
194
203
|
test_files: []
|