ethlite 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Manifest.txt +2 -0
- data/Rakefile +1 -1
- data/lib/digest/keccak256.rb +111 -0
- data/lib/digest/sha3.rb +108 -0
- data/lib/ethlite/abi/utils.rb +5 -1
- data/lib/ethlite/version.rb +1 -1
- data/lib/ethlite.rb +4 -1
- metadata +3 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5dea4d9654501b9b1fa7a86477a0b509e7722975fdf29ce3c95e060750d917f7
|
4
|
+
data.tar.gz: 25b082b2803cb0404b39cab23b62740c716680f22d3f61825e364f9dfd387640
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c28f0334a44bdbb3c2b4d2f375b94ff9ee643a49aa66953eac3bcd471a78398f2c89f8f8b150f64a1d64d19c2a47590f793b4c88ab7c41c045330a44a85a06b
|
7
|
+
data.tar.gz: 45ff4d1b251eb7273f8fa1034b92bb2a95164796268e2d0a69d26f3567e7b806163ab7d851ef8d314d75bb61845d0117ae56fd7af089098ff43e3940dc1c7b2d
|
data/Manifest.txt
CHANGED
data/Rakefile
CHANGED
@@ -0,0 +1,111 @@
|
|
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
|
+
module Digest
|
12
|
+
class Keccak256 < Digest::Class
|
13
|
+
PILN = [10, 7, 11, 17, 18, 3, 5, 16,
|
14
|
+
8, 21, 24, 4, 15, 23, 19, 13,
|
15
|
+
12, 2, 20, 14, 22, 9, 6, 1]
|
16
|
+
|
17
|
+
ROTC = [ 1, 3, 6, 10, 15, 21, 28, 36,
|
18
|
+
45, 55, 2, 14, 27, 41, 56, 8,
|
19
|
+
25, 43, 62, 18, 39, 61, 20, 44]
|
20
|
+
|
21
|
+
RNDC = [0x0000000000000001, 0x0000000000008082, 0x800000000000808a,
|
22
|
+
0x8000000080008000, 0x000000000000808b, 0x0000000080000001,
|
23
|
+
0x8000000080008081, 0x8000000000008009, 0x000000000000008a,
|
24
|
+
0x0000000000000088, 0x0000000080008009, 0x000000008000000a,
|
25
|
+
0x000000008000808b, 0x800000000000008b, 0x8000000000008089,
|
26
|
+
0x8000000000008003, 0x8000000000008002, 0x8000000000000080,
|
27
|
+
0x000000000000800a, 0x800000008000000a, 0x8000000080008081,
|
28
|
+
0x8000000000008080, 0x0000000080000001, 0x8000000080008008]
|
29
|
+
|
30
|
+
def initialize
|
31
|
+
@size = 256 / 8
|
32
|
+
@buffer = ''
|
33
|
+
end
|
34
|
+
|
35
|
+
def << s
|
36
|
+
@buffer << s
|
37
|
+
self
|
38
|
+
end
|
39
|
+
alias update <<
|
40
|
+
|
41
|
+
def reset
|
42
|
+
@buffer.clear
|
43
|
+
self
|
44
|
+
end
|
45
|
+
|
46
|
+
def finish
|
47
|
+
s = Array.new 25, 0
|
48
|
+
width = 200 - @size * 2
|
49
|
+
padding = "\x01"
|
50
|
+
|
51
|
+
buffer = @buffer
|
52
|
+
buffer << padding << "\0" * (width - buffer.size % width)
|
53
|
+
buffer[-1] = (buffer[-1].ord | 0x80).chr
|
54
|
+
|
55
|
+
0.step buffer.size - 1, width do |j|
|
56
|
+
quads = buffer[j, width].unpack 'Q*'
|
57
|
+
(width / 8).times do |i|
|
58
|
+
s[i] ^= quads[i]
|
59
|
+
end
|
60
|
+
|
61
|
+
keccak s
|
62
|
+
end
|
63
|
+
|
64
|
+
s.pack('Q*')[0, @size]
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
def keccak s
|
69
|
+
24.times.each_with_object [] do |round, a|
|
70
|
+
# Theta
|
71
|
+
5.times do |i|
|
72
|
+
a[i] = s[i] ^ s[i + 5] ^ s[i + 10] ^ s[i + 15] ^ s[i + 20]
|
73
|
+
end
|
74
|
+
|
75
|
+
5.times do |i|
|
76
|
+
t = a[(i + 4) % 5] ^ rotate(a[(i + 1) % 5], 1)
|
77
|
+
0.step 24, 5 do |j|
|
78
|
+
s[j + i] ^= t
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# Rho Pi
|
83
|
+
t = s[1]
|
84
|
+
24.times do |i|
|
85
|
+
j = PILN[i]
|
86
|
+
a[0] = s[j]
|
87
|
+
s[j] = rotate t, ROTC[i]
|
88
|
+
t = a[0]
|
89
|
+
end
|
90
|
+
|
91
|
+
# Chi
|
92
|
+
0.step 24, 5 do |j|
|
93
|
+
5.times do |i|
|
94
|
+
a[i] = s[j + i]
|
95
|
+
end
|
96
|
+
|
97
|
+
5.times do |i|
|
98
|
+
s[j + i] ^= ~a[(i + 1) % 5] & a[(i + 2) % 5]
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
# Iota
|
103
|
+
s[0] ^= RNDC[round]
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def rotate x, y
|
108
|
+
(x << y | x >> 64 - y) & (1 << 64) - 1
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
data/lib/digest/sha3.rb
ADDED
@@ -0,0 +1,108 @@
|
|
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
|
+
module Digest
|
10
|
+
class SHA3 < Digest::Class
|
11
|
+
PILN = [10, 7, 11, 17, 18, 3, 5, 16,
|
12
|
+
8, 21, 24, 4, 15, 23, 19, 13,
|
13
|
+
12, 2, 20, 14, 22, 9, 6, 1]
|
14
|
+
|
15
|
+
ROTC = [ 1, 3, 6, 10, 15, 21, 28, 36,
|
16
|
+
45, 55, 2, 14, 27, 41, 56, 8,
|
17
|
+
25, 43, 62, 18, 39, 61, 20, 44]
|
18
|
+
|
19
|
+
RNDC = [0x0000000000000001, 0x0000000000008082, 0x800000000000808a,
|
20
|
+
0x8000000080008000, 0x000000000000808b, 0x0000000080000001,
|
21
|
+
0x8000000080008081, 0x8000000000008009, 0x000000000000008a,
|
22
|
+
0x0000000000000088, 0x0000000080008009, 0x000000008000000a,
|
23
|
+
0x000000008000808b, 0x800000000000008b, 0x8000000000008089,
|
24
|
+
0x8000000000008003, 0x8000000000008002, 0x8000000000000080,
|
25
|
+
0x000000000000800a, 0x800000008000000a, 0x8000000080008081,
|
26
|
+
0x8000000000008080, 0x0000000080000001, 0x8000000080008008]
|
27
|
+
|
28
|
+
def initialize hash_size = 512
|
29
|
+
@size = hash_size / 8
|
30
|
+
@buffer = ''
|
31
|
+
end
|
32
|
+
|
33
|
+
def << s
|
34
|
+
@buffer << s
|
35
|
+
self
|
36
|
+
end
|
37
|
+
alias update <<
|
38
|
+
|
39
|
+
def reset
|
40
|
+
@buffer.clear
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
def finish
|
45
|
+
s = Array.new 25, 0
|
46
|
+
width = 200 - @size * 2
|
47
|
+
|
48
|
+
buffer = @buffer
|
49
|
+
buffer << "\x06" << "\0" * (width - buffer.size % width)
|
50
|
+
buffer[-1] = (buffer[-1].ord | 0x80).chr
|
51
|
+
|
52
|
+
0.step buffer.size - 1, width do |j|
|
53
|
+
quads = buffer[j, width].unpack 'Q*'
|
54
|
+
(width / 8).times do |i|
|
55
|
+
s[i] ^= quads[i]
|
56
|
+
end
|
57
|
+
|
58
|
+
keccak s
|
59
|
+
end
|
60
|
+
|
61
|
+
s.pack('Q*')[0, @size]
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
def keccak s
|
66
|
+
24.times.each_with_object [] do |round, a|
|
67
|
+
# Theta
|
68
|
+
5.times do |i|
|
69
|
+
a[i] = s[i] ^ s[i + 5] ^ s[i + 10] ^ s[i + 15] ^ s[i + 20]
|
70
|
+
end
|
71
|
+
|
72
|
+
5.times do |i|
|
73
|
+
t = a[(i + 4) % 5] ^ rotate(a[(i + 1) % 5], 1)
|
74
|
+
0.step 24, 5 do |j|
|
75
|
+
s[j + i] ^= t
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# Rho Pi
|
80
|
+
t = s[1]
|
81
|
+
24.times do |i|
|
82
|
+
j = PILN[i]
|
83
|
+
a[0] = s[j]
|
84
|
+
s[j] = rotate t, ROTC[i]
|
85
|
+
t = a[0]
|
86
|
+
end
|
87
|
+
|
88
|
+
# Chi
|
89
|
+
0.step 24, 5 do |j|
|
90
|
+
5.times do |i|
|
91
|
+
a[i] = s[j + i]
|
92
|
+
end
|
93
|
+
|
94
|
+
5.times do |i|
|
95
|
+
s[j + i] ^= ~a[(i + 1) % 5] & a[(i + 2) % 5]
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
# Iota
|
100
|
+
s[0] ^= RNDC[round]
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def rotate x, y
|
105
|
+
(x << y | x >> 64 - y) & (1 << 64) - 1
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
data/lib/ethlite/abi/utils.rb
CHANGED
@@ -11,13 +11,17 @@ module Abi
|
|
11
11
|
#
|
12
12
|
def keccak256(x)
|
13
13
|
# Digest::SHA3.new(256).digest(x)
|
14
|
-
Digest::Keccak.digest(x, 256)
|
14
|
+
## Digest::Keccak.digest(x, 256)
|
15
|
+
Digest::Keccak256.digest( x )
|
15
16
|
end
|
16
17
|
|
18
|
+
=begin
|
19
|
+
## check where required / in use - what for?
|
17
20
|
def keccak512(x)
|
18
21
|
# Digest::SHA3.new(512).digest(x)
|
19
22
|
Digest::Keccak.digest(x, 512)
|
20
23
|
end
|
24
|
+
=end
|
21
25
|
|
22
26
|
def keccak256_rlp(x)
|
23
27
|
keccak256 RLP.encode(x)
|
data/lib/ethlite/version.rb
CHANGED
data/lib/ethlite.rb
CHANGED
@@ -10,9 +10,12 @@ require 'openssl'
|
|
10
10
|
require 'digest'
|
11
11
|
|
12
12
|
## 3rd party gems
|
13
|
-
require 'digest/keccak' ## gem keccak - see https://rubygems.org/gems/keccak
|
14
13
|
require 'rlp' ## gem rlp - see https://rubygems.org/gems/rlp
|
15
14
|
|
15
|
+
## bundled require 'digest/keccak' ## gem keccak - see https://rubygems.org/gems/keccak
|
16
|
+
require 'digest/keccak256'
|
17
|
+
|
18
|
+
|
16
19
|
|
17
20
|
|
18
21
|
## our own code
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ethlite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: keccak
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: rlp
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,6 +86,8 @@ files:
|
|
100
86
|
- Manifest.txt
|
101
87
|
- README.md
|
102
88
|
- Rakefile
|
89
|
+
- lib/digest/keccak256.rb
|
90
|
+
- lib/digest/sha3.rb
|
103
91
|
- lib/ethlite.rb
|
104
92
|
- lib/ethlite/abi/abi_coder.rb
|
105
93
|
- lib/ethlite/abi/constant.rb
|