ethlite 0.2.0 → 0.2.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: 9ee22cabcf4a413047cd733de839213fefe59ea3a45ddc353f9dd7675f416e28
4
- data.tar.gz: c16a6e278a4102061f6efbf7908171ab04653108b2abd4c9d8507ab7bba46324
3
+ metadata.gz: bdacaafee691ecb72746721479d637e03b211c4afbcde0c4c938edc50695ccf8
4
+ data.tar.gz: 607cb3eda84667009ac105e998afb56a4af0dfa23dcc0a47264623e8e3409c21
5
5
  SHA512:
6
- metadata.gz: 356dd2d7d825fe42d30e94d48b58d8a737ee0cd274e1329c9425341d953e0654ac1a34d789c5f98ca52706b3f1f0702a7d4a418d758a76856410ae72f1bc1b1a
7
- data.tar.gz: 0512f202e3b4eefb7a2115158036cd4e11813ef37f0b4df3a9e8269b50f90d8c2fa8d6ae6cade9caf9a49a96b30556ef28e2afa5d8debfe8d2ebf95c221b64a0
6
+ metadata.gz: 459910398810dfa9ff9dab030feb0a185a03afa5d440656cc37ef4479dd54f49e0cd16b9c7e018b72d3a9507c109deb01e234f408e5b13131f14d044701868be
7
+ data.tar.gz: 6783748547fa38964c62f695df60d4d5f8533fceb650c212e4ae0d6f20619cd9f42dea747f1a0c3bc28512b336998cde5c80fce78e4c3445a6e3723e05a5c54d
data/Manifest.txt CHANGED
@@ -2,6 +2,8 @@ CHANGELOG.md
2
2
  Manifest.txt
3
3
  README.md
4
4
  Rakefile
5
+ lib/digest/keccak256.rb
6
+ lib/digest/sha3.rb
5
7
  lib/ethlite.rb
6
8
  lib/ethlite/abi/abi_coder.rb
7
9
  lib/ethlite/abi/constant.rb
data/Rakefile CHANGED
@@ -20,7 +20,7 @@ Hoe.spec 'ethlite' do
20
20
 
21
21
  self.extra_deps = [
22
22
  ['cocos'],
23
- ['keccak'],
23
+ ## ['keccak'], -- try using bundled ruby version for now
24
24
  ['rlp'],
25
25
  ]
26
26
 
@@ -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
@@ -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
@@ -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)
@@ -3,7 +3,7 @@
3
3
  module Ethlite
4
4
  MAJOR = 0
5
5
  MINOR = 2
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
@@ -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
@@ -33,6 +36,25 @@ require_relative 'ethlite/contract'
33
36
 
34
37
 
35
38
 
39
+
40
+ module Ethlite
41
+ class Configuration
42
+ def rpc() @rpc || Rpc.new( ENV['INFURA_URI'] ); end
43
+ def rpc=(value) @rpc = value; end
44
+ end # class Configuration
45
+
46
+
47
+ ## lets you use
48
+ ## Ethlite.configure do |config|
49
+ ## config.rpc = Ethlite::Rpc.new( ENV['INFURA_URI'] )
50
+ ## end
51
+ def self.configure() yield( config ); end
52
+ def self.config() @config ||= Configuration.new; end
53
+ end # module Ethlite
54
+
55
+
56
+
57
+
36
58
  ## add convenience alternate spelling
37
59
  EthLite = Ethlite
38
60
 
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.0
4
+ version: 0.2.2
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