ciri 0.0.0

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.
data/lib/ciri/utils.rb ADDED
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2018, by Jiang Jinyang. <https://justjjy.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+
24
+ require 'digest/sha3'
25
+
26
+ module Ciri
27
+ module Utils
28
+
29
+ class << self
30
+ def sha3(*data)
31
+ s = Digest::SHA3.new(256)
32
+ data.each {|i| s.update(i)}
33
+ s.digest
34
+ end
35
+
36
+ def secret_compare(s1, s2)
37
+ s1.size == s2.size && s1.each_byte.each_with_index.map {|b, i| b ^ s2[i].ord}.reduce(0, :+) == 0
38
+ end
39
+
40
+ def big_endian_encode(n, zero = '')
41
+ if n == 0
42
+ zero
43
+ else
44
+ big_endian_encode(n / 256) + (n % 256).chr
45
+ end
46
+ end
47
+
48
+ def big_endian_decode(input)
49
+ input.each_byte.reduce(0) {|s, i| s * 256 + i}
50
+ end
51
+
52
+ def hex_to_data(hex)
53
+ [hex].pack("H*")
54
+ end
55
+
56
+ def data_to_hex(data)
57
+ data.unpack("H*").first
58
+ end
59
+
60
+ def create_ec_pk(raw_pubkey: nil, raw_privkey: nil)
61
+ public_key = raw_pubkey && begin
62
+ group = OpenSSL::PKey::EC::Group.new('secp256k1')
63
+ bn = OpenSSL::BN.new(raw_pubkey, 2)
64
+ OpenSSL::PKey::EC::Point.new(group, bn)
65
+ end
66
+
67
+ OpenSSL::PKey::EC.new('secp256k1').tap do |key|
68
+ key.public_key = public_key if public_key
69
+ key.private_key = OpenSSL::BN.new(raw_privkey, 2) if raw_privkey
70
+ end
71
+ end
72
+ end
73
+
74
+ end
75
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ciri
4
+ VERSION = "0.0.0"
5
+ end
metadata ADDED
@@ -0,0 +1,179 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ciri
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jiang Jinyang
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-05-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: digest-sha3
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bitcoin-secp256k1
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.4.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.4.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: concurrent-ruby
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.0.5
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.5
55
+ - !ruby/object:Gem::Dependency
56
+ name: snappy
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.0.17
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.0.17
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.16'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.16'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ description: Ciri project intent to implement full feature set of ethereum in pure
112
+ ruby, to provide both usable cli and well documented ruby library.
113
+ email:
114
+ - jjyruby@gmail.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".travis.yml"
122
+ - CODE_OF_CONDUCT.md
123
+ - Gemfile
124
+ - Gemfile.lock
125
+ - LICENSE.txt
126
+ - README.md
127
+ - Rakefile
128
+ - bin/console
129
+ - bin/setup
130
+ - ciri.gemspec
131
+ - lib/ciri.rb
132
+ - lib/ciri/crypto.rb
133
+ - lib/ciri/devp2p/actor.rb
134
+ - lib/ciri/devp2p/peer.rb
135
+ - lib/ciri/devp2p/protocol.rb
136
+ - lib/ciri/devp2p/protocol_io.rb
137
+ - lib/ciri/devp2p/rlpx.rb
138
+ - lib/ciri/devp2p/rlpx/connection.rb
139
+ - lib/ciri/devp2p/rlpx/encryption_handshake.rb
140
+ - lib/ciri/devp2p/rlpx/error.rb
141
+ - lib/ciri/devp2p/rlpx/frame_io.rb
142
+ - lib/ciri/devp2p/rlpx/message.rb
143
+ - lib/ciri/devp2p/rlpx/node.rb
144
+ - lib/ciri/devp2p/rlpx/protocol_handshake.rb
145
+ - lib/ciri/devp2p/rlpx/protocol_messages.rb
146
+ - lib/ciri/devp2p/rlpx/secrets.rb
147
+ - lib/ciri/devp2p/server.rb
148
+ - lib/ciri/key.rb
149
+ - lib/ciri/rlp.rb
150
+ - lib/ciri/rlp/decode.rb
151
+ - lib/ciri/rlp/encode.rb
152
+ - lib/ciri/rlp/serializable.rb
153
+ - lib/ciri/utils.rb
154
+ - lib/ciri/version.rb
155
+ homepage: https://github.com/ruby-ethereum/ethereum
156
+ licenses:
157
+ - MIT
158
+ metadata: {}
159
+ post_install_message:
160
+ rdoc_options: []
161
+ require_paths:
162
+ - lib
163
+ required_ruby_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ required_rubygems_version: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ requirements: []
174
+ rubyforge_project:
175
+ rubygems_version: 2.7.3
176
+ signing_key:
177
+ specification_version: 4
178
+ summary: Ruby implementation of the ethereum
179
+ test_files: []