ethlite 0.3.0 → 0.3.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4c28e1b125fefa2964c88a020a14de2d0e95c412e16f50ba5a329382465ccf8
4
- data.tar.gz: 324e941a6825091bbf88539eb31acd03b80e8732c61442580a092bbdefe4e845
3
+ metadata.gz: a543bc0ff77f147cf1d33e68db8b72345f705401061348c1c6ce7b96c410bd43
4
+ data.tar.gz: ccc325256399a94b4c3ade2292b04592305e14d2ca70c2fe8a203ab2f185f029
5
5
  SHA512:
6
- metadata.gz: df7dae52f733638a324dceb46371e1ecf6043f75515dc75ced197dfe1e24194b91e75f693f441861a122294e5d2408338584ee2b41a94ff64a277c0739fc9f8f
7
- data.tar.gz: 171eea690f22474462316642eea60971eed702b6604681c3126b5900a134c196eb7cd07111d304086410e3ff46ccf7d73c61b2570c3430e563502ee6bf7e55ba
6
+ metadata.gz: fac7091c8758f9df8a43fff5b61ce03d2a06e9d47a39d592e5da797ef2aa52ca24bc29f582e47624728d9129e2cd511a51be9b426443d7a6155f71975057a589
7
+ data.tar.gz: d9ec99feb5c27b6d108ea6cfc0cc08e30b88d1a883a009f92b361732fbc75b409e47681b9198b3bb343626a04e8b35278ac6db89bd87569128956cd52462b3b1
data/Manifest.txt CHANGED
@@ -2,8 +2,6 @@ CHANGELOG.md
2
2
  Manifest.txt
3
3
  README.md
4
4
  Rakefile
5
- lib/digest/keccak.rb
6
- lib/digest/sha3.rb
7
5
  lib/ethlite.rb
8
6
  lib/ethlite/abi/codec.rb
9
7
  lib/ethlite/abi/type.rb
data/README.md CHANGED
@@ -16,10 +16,10 @@ ethlite - light-weight machinery to query / call ethereum (blockchain contract)
16
16
 
17
17
  ### Step 0: Setup JSON RPC Client
18
18
 
19
+ Let's use the simple (built-in) JSON RPC client.
20
+ Get the eth node uri via the INFURA_URI enviroment variable / key e.g. `https://mainnet.infura.io/v3/<YOUR_KEY_HERE>`:
21
+
19
22
  ```ruby
20
- ## let's use a simple JSON RPC client
21
- ## get the eth node uri via the INFURA_URI enviroment variable / key
22
- ## e.g. https://mainnet.infura.io/v3/<YOUR_KEY_HERE>
23
23
  ETH_NODE = JsonRpc.new( ENV['INFURA_URI'] )
24
24
  ```
25
25
 
data/Rakefile CHANGED
@@ -20,8 +20,8 @@ Hoe.spec 'ethlite' do
20
20
 
21
21
  self.extra_deps = [
22
22
  ['cocos'],
23
- ## ['keccak'], -- try using bundled ruby version for now
24
23
  ['rlp-lite'],
24
+ ['digest-lite'],
25
25
  ]
26
26
 
27
27
  self.licenses = ['Public Domain']
@@ -2,16 +2,13 @@
2
2
 
3
3
  module Ethlite
4
4
  module Abi
5
- extend self
6
5
 
7
6
  ##
8
7
  # Contract ABI encoding and decoding.
9
8
  #
10
9
  # @see https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI
11
10
  #
12
- module Codec
13
- extend self
14
-
11
+ class Codec
15
12
  class EncodingError < StandardError; end
16
13
  class DecodingError < StandardError; end
17
14
  class ValueError < StandardError; end
@@ -412,19 +409,23 @@ module Ethlite
412
409
  raise EncodingError, "Cannot decode int: #{n}"
413
410
  end
414
411
  end
415
- end # module Codec
412
+ end # class Codec
413
+
416
414
 
417
415
 
418
416
 
419
417
 
420
418
 
419
+ def self.codec
420
+ @codec ||= Codec.new
421
+ end
421
422
 
422
- def encode_abi(types, args)
423
- Codec.encode_abi( types, args )
423
+ def self.encode_abi(types, args)
424
+ codec.encode_abi( types, args )
424
425
  end
425
426
 
426
- def decode_abi(types, data, raise_errors = false)
427
- Codec.decode_abi( types, data, raise_errors )
427
+ def self.decode_abi(types, data, raise_errors = false)
428
+ codec.decode_abi( types, data, raise_errors )
428
429
  end
429
430
 
430
431
 
@@ -117,8 +117,8 @@ module Ethlite
117
117
  def subtype
118
118
  @subtype ||= self.class.new(base, sub, dims[0...-1])
119
119
  end
120
+ end # class Type
120
121
 
121
- end
122
122
 
123
123
  class Tuple < Type
124
124
 
@@ -193,7 +193,7 @@ module Ethlite
193
193
  def subtype
194
194
  @subtype ||= Tuple.new(types, dims[0...-1])
195
195
  end
196
- end
196
+ end # class Tuple
197
197
 
198
198
 
199
199
  end # module Abi
data/lib/ethlite/utils.rb CHANGED
@@ -1,8 +1,7 @@
1
1
  module Ethlite
2
- module Utils
3
2
 
4
- extend self
5
3
 
4
+ module UtilHelper
6
5
  ##
7
6
  # Not the keccak in sha3, although it's underlying lib named SHA3
8
7
  #
@@ -211,12 +210,17 @@ module Utils
211
210
  end
212
211
  end
213
212
 
214
-
215
-
216
213
  def signature_hash( signature, length=8 )
217
214
  encode_hex( keccak256(signature) )[0...length]
218
215
  end
219
216
 
220
- end # module Utils
217
+ end # module UtilHelper
218
+
219
+
220
+
221
+ module Utils
222
+ extend UtilHelper
223
+ end
224
+
221
225
  end # module Ethlite
222
226
 
@@ -3,7 +3,7 @@
3
3
  module Ethlite
4
4
  MAJOR = 0
5
5
  MINOR = 3
6
- PATCH = 0
6
+ PATCH = 2
7
7
  VERSION = [MAJOR,MINOR,PATCH].join('.')
8
8
 
9
9
  def self.version
data/lib/ethlite.rb CHANGED
@@ -11,15 +11,12 @@ require 'digest'
11
11
 
12
12
  ## 3rd party gems
13
13
  require 'rlp-lite'
14
+ require 'digest-lite'
14
15
 
15
- ## bundled require 'digest/keccak' ## gem keccak - see https://rubygems.org/gems/keccak
16
- require_relative 'digest/keccak'
17
- require_relative 'digest/sha3'
18
16
 
19
17
  require_relative 'jsonrpc/jsonrpc'
20
18
 
21
19
 
22
-
23
20
  ## our own code
24
21
  require_relative 'ethlite/version' # note: let version always go first
25
22
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ethlite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-21 00:00:00.000000000 Z
11
+ date: 2022-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cocos
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: digest-lite
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rdoc
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -86,8 +100,6 @@ files:
86
100
  - Manifest.txt
87
101
  - README.md
88
102
  - Rakefile
89
- - lib/digest/keccak.rb
90
- - lib/digest/sha3.rb
91
103
  - lib/ethlite.rb
92
104
  - lib/ethlite/abi/codec.rb
93
105
  - lib/ethlite/abi/type.rb
data/lib/digest/keccak.rb DELETED
@@ -1,125 +0,0 @@
1
- ###
2
- # use a "vendor" bundled keccak 256 in all ruby (no c-extensions required)
3
- #
4
- # see https://github.com/evtaylor/keccak256
5
-
6
-
7
-
8
- ## require 'digest'
9
-
10
-
11
-
12
- ##
13
- # note: use KeccakLite (or KeccakZero? KeccakSHA3?) instead of Keccak
14
- # to allow usage of native w/ c-extension Keccak and "lite" version
15
-
16
-
17
-
18
- module Digest
19
- class KeccakLite < Digest::Class
20
- PILN = [10, 7, 11, 17, 18, 3, 5, 16,
21
- 8, 21, 24, 4, 15, 23, 19, 13,
22
- 12, 2, 20, 14, 22, 9, 6, 1]
23
-
24
- ROTC = [ 1, 3, 6, 10, 15, 21, 28, 36,
25
- 45, 55, 2, 14, 27, 41, 56, 8,
26
- 25, 43, 62, 18, 39, 61, 20, 44]
27
-
28
- RNDC = [0x0000000000000001, 0x0000000000008082, 0x800000000000808a,
29
- 0x8000000080008000, 0x000000000000808b, 0x0000000080000001,
30
- 0x8000000080008081, 0x8000000000008009, 0x000000000000008a,
31
- 0x0000000000000088, 0x0000000080008009, 0x000000008000000a,
32
- 0x000000008000808b, 0x800000000000008b, 0x8000000000008089,
33
- 0x8000000000008003, 0x8000000000008002, 0x8000000000000080,
34
- 0x000000000000800a, 0x800000008000000a, 0x8000000080008081,
35
- 0x8000000000008080, 0x0000000080000001, 0x8000000080008008]
36
-
37
- ## note: changed initialize to use param hash_size = 512
38
- ## do NOT hard-code only 256 bit
39
- def initialize( hash_size = 512 )
40
- @size = hash_size / 8
41
- @buffer = ''
42
- end
43
-
44
- def <<( s )
45
- @buffer << s
46
- self
47
- end
48
- alias_method :update, :<<
49
-
50
- def reset
51
- @buffer.clear
52
- self
53
- end
54
-
55
- def finish
56
- s = Array.new( 25, 0 )
57
- width = 200 - @size * 2
58
-
59
- ### note: padding changed in final FIPS PUB 202 standard
60
- ## from "\x01" to "\x06"
61
- padding = "\x01"
62
-
63
- buffer = @buffer
64
- buffer << padding << "\0" * (width - buffer.size % width)
65
- buffer[-1] = (buffer[-1].ord | 0x80).chr
66
-
67
- 0.step( buffer.size - 1, width ) do |j|
68
- quads = buffer[j, width].unpack( 'Q*' )
69
- (width / 8).times do |i|
70
- s[i] ^= quads[i]
71
- end
72
-
73
- _keccak( s )
74
- end
75
-
76
- s.pack('Q*')[0, @size]
77
- end
78
-
79
- private
80
- def _keccak( s )
81
- 24.times.each_with_object( [] ) do |round, a|
82
- # Theta
83
- 5.times do |i|
84
- a[i] = s[i] ^ s[i + 5] ^ s[i + 10] ^ s[i + 15] ^ s[i + 20]
85
- end
86
-
87
- 5.times do |i|
88
- t = a[(i + 4) % 5] ^ _rotate(a[(i + 1) % 5], 1)
89
- 0.step( 24, 5 ) do |j|
90
- s[j + i] ^= t
91
- end
92
- end
93
-
94
- # Rho Pi
95
- t = s[1]
96
- 24.times do |i|
97
- j = PILN[i]
98
- a[0] = s[j]
99
- s[j] = _rotate( t, ROTC[i] )
100
- t = a[0]
101
- end
102
-
103
- # Chi
104
- 0.step( 24, 5 ) do |j|
105
- 5.times do |i|
106
- a[i] = s[j + i]
107
- end
108
-
109
- 5.times do |i|
110
- s[j + i] ^= ~a[(i + 1) % 5] & a[(i + 2) % 5]
111
- end
112
- end
113
-
114
- # Iota
115
- s[0] ^= RNDC[round]
116
- end
117
- end
118
-
119
- def _rotate( x, y )
120
- (x << y | x >> 64 - y) & (1 << 64) - 1
121
- end
122
-
123
-
124
- end # class KeccakLite
125
- end # module Digest
data/lib/digest/sha3.rb DELETED
@@ -1,118 +0,0 @@
1
- ###
2
- # use a "vendor" bundled sha3 in all ruby (no c-extensions required)
3
- #
4
- # see https://github.com/havenwood/sha3-pure-ruby/blob/master/lib/sha3-pure-ruby.rb
5
-
6
-
7
- ## require 'digest'
8
-
9
- ##
10
- # note: use SHA3Lite (or SHA3Zero? ZeroSHA3?) instead of SHA3
11
- # to allow usage of native w/ c-extension SHA3 and "lite" version
12
-
13
-
14
- module Digest
15
- class SHA3Lite < Digest::Class
16
- PILN = [10, 7, 11, 17, 18, 3, 5, 16,
17
- 8, 21, 24, 4, 15, 23, 19, 13,
18
- 12, 2, 20, 14, 22, 9, 6, 1]
19
-
20
- ROTC = [ 1, 3, 6, 10, 15, 21, 28, 36,
21
- 45, 55, 2, 14, 27, 41, 56, 8,
22
- 25, 43, 62, 18, 39, 61, 20, 44]
23
-
24
- RNDC = [0x0000000000000001, 0x0000000000008082, 0x800000000000808a,
25
- 0x8000000080008000, 0x000000000000808b, 0x0000000080000001,
26
- 0x8000000080008081, 0x8000000000008009, 0x000000000000008a,
27
- 0x0000000000000088, 0x0000000080008009, 0x000000008000000a,
28
- 0x000000008000808b, 0x800000000000008b, 0x8000000000008089,
29
- 0x8000000000008003, 0x8000000000008002, 0x8000000000000080,
30
- 0x000000000000800a, 0x800000008000000a, 0x8000000080008081,
31
- 0x8000000000008080, 0x0000000080000001, 0x8000000080008008]
32
-
33
- def initialize( hash_size = 512 )
34
- @size = hash_size / 8
35
- @buffer = '' ## todo/check: make sure buffer is with encoding BINARY - why? why not?
36
- end
37
-
38
- def <<( s )
39
- @buffer << s
40
- self
41
- end
42
- alias_method :update, :<<
43
-
44
- def reset
45
- @buffer.clear
46
- self
47
- end
48
-
49
- def finish
50
- s = Array.new( 25, 0 )
51
- width = 200 - @size * 2
52
-
53
- ### note: padding changed in final FIPS PUB 202 standard
54
- ## from "\x01" to "\x06"
55
- padding = "\x06"
56
-
57
- buffer = @buffer
58
- buffer << padding << "\0" * (width - buffer.size % width)
59
- buffer[-1] = (buffer[-1].ord | 0x80).chr
60
-
61
- 0.step( buffer.size - 1, width ) do |j|
62
- quads = buffer[j, width].unpack( 'Q*' )
63
- (width / 8).times do |i|
64
- s[i] ^= quads[i]
65
- end
66
-
67
- _keccak( s )
68
- end
69
-
70
- s.pack('Q*')[0, @size]
71
- end
72
-
73
- private
74
- def _keccak( s )
75
- 24.times.each_with_object( [] ) do |round, a|
76
- # Theta
77
- 5.times do |i|
78
- a[i] = s[i] ^ s[i + 5] ^ s[i + 10] ^ s[i + 15] ^ s[i + 20]
79
- end
80
-
81
- 5.times do |i|
82
- t = a[(i + 4) % 5] ^ _rotate(a[(i + 1) % 5], 1)
83
- 0.step( 24, 5 ) do |j|
84
- s[j + i] ^= t
85
- end
86
- end
87
-
88
- # Rho Pi
89
- t = s[1]
90
- 24.times do |i|
91
- j = PILN[i]
92
- a[0] = s[j]
93
- s[j] = _rotate( t, ROTC[i] )
94
- t = a[0]
95
- end
96
-
97
- # Chi
98
- 0.step( 24, 5 ) do |j|
99
- 5.times do |i|
100
- a[i] = s[j + i]
101
- end
102
-
103
- 5.times do |i|
104
- s[j + i] ^= ~a[(i + 1) % 5] & a[(i + 2) % 5]
105
- end
106
- end
107
-
108
- # Iota
109
- s[0] ^= RNDC[round]
110
- end
111
- end
112
-
113
- def _rotate( x, y )
114
- (x << y | x >> 64 - y) & (1 << 64) - 1
115
- end
116
-
117
- end # class SHA3Lite
118
- end # module Digest