ethlite 0.3.1 → 0.3.2

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
  SHA256:
3
- metadata.gz: a91770dc04d591bf88353b4783080812f1659a7f679f09636b656a1a8d9ac7b7
4
- data.tar.gz: 626dda3168008abf7743526be783722292af40633c4acbe1bea4ea649f77a602
3
+ metadata.gz: a543bc0ff77f147cf1d33e68db8b72345f705401061348c1c6ce7b96c410bd43
4
+ data.tar.gz: ccc325256399a94b4c3ade2292b04592305e14d2ca70c2fe8a203ab2f185f029
5
5
  SHA512:
6
- metadata.gz: 31b7dce9e0b71c4ea56697272d731541ecd58fdbfac6d5a3ddc949f7d47263340fda578d37403f788ecc02b7b08152d75107fd856f4af54b256c1cbb52b55ab2
7
- data.tar.gz: 852410528fc380e40cff8fd4eafd49a2697947d2b2a4ab73b6210c88c87c45ecfdd2c44c296dd473cb7a5e5c7d175625d774e3fb6f88a45da7f3356af2b21ea6
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']
@@ -3,7 +3,7 @@
3
3
  module Ethlite
4
4
  MAJOR = 0
5
5
  MINOR = 3
6
- PATCH = 1
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.1
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-22 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