beowulf-ruby-testnet 0.0.2 → 0.0.3
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 +4 -4
- data/lib/beowulf/type/authority.rb +1 -1
- data/lib/beowulf/type/authority_update.rb +1 -1
- data/lib/beowulf/version.rb +1 -1
- data/lib/beowulf/wallet.rb +85 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27e0e138da847a7dc047b8fa71ab61c3e0ae9155e6b17b32deafc481ea6e6b16
|
4
|
+
data.tar.gz: 63fcc9da2cd8ddc534c21eaa7d7563d1a8e0387abce1f418ab950235469c9891
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3371235a6ee5ef9b49958c551f8d4263d968ad9239cd5cf8294a7c7a2ff0bdf162f31428b4b75a641969c59e3c98255ff0ad927b168a83e164203be0587551c4
|
7
|
+
data.tar.gz: 7d9777a57077c4504ccf009f35bf539b8c06a0e3d7b778e078d10e38b45867de09596bc6dd7ae56e20638c0403e8a26ce6bc7b805d3d66dadd49c573fb1b6a94
|
data/lib/beowulf/version.rb
CHANGED
data/lib/beowulf/wallet.rb
CHANGED
@@ -8,6 +8,8 @@ module Beowulf
|
|
8
8
|
include ChainConfig
|
9
9
|
include Utils
|
10
10
|
|
11
|
+
attr_accessor :name, :private_key, :public_key, :cipher_keys, :cipher_type, :salt
|
12
|
+
|
11
13
|
def initialize(options = {})
|
12
14
|
@name = options[:name] || ''
|
13
15
|
@private_key = options[:private_key] || ''
|
@@ -17,16 +19,15 @@ module Beowulf
|
|
17
19
|
@salt = options[:salt] || ''
|
18
20
|
end
|
19
21
|
|
20
|
-
def
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
@public_key
|
22
|
+
def to_json(options = {})
|
23
|
+
JSON.dump ({
|
24
|
+
:name => @name,
|
25
|
+
:private_key => @private_key,
|
26
|
+
:public_key => @public_key,
|
27
|
+
:cipher_keys => @cipher_keys,
|
28
|
+
:cipher_type => @cipher_type,
|
29
|
+
:salt => @salt
|
30
|
+
})
|
30
31
|
end
|
31
32
|
|
32
33
|
def gen_keys
|
@@ -142,6 +143,41 @@ module Beowulf
|
|
142
143
|
File.open(file_path, "w") { |file| file.puts wallet_json}
|
143
144
|
end
|
144
145
|
|
146
|
+
def encode_wallet(password)
|
147
|
+
# Validate
|
148
|
+
if @name == nil || @name.length == 0
|
149
|
+
puts "name is not empty."
|
150
|
+
raise WalletError, "name is not empty."
|
151
|
+
end
|
152
|
+
|
153
|
+
# Encrypt data
|
154
|
+
# Create checksum
|
155
|
+
@salt = SecureRandom.alphanumeric(16)
|
156
|
+
new_password = password + @salt
|
157
|
+
# puts "new_password:", new_password
|
158
|
+
pw_bytes = pakStr(new_password)
|
159
|
+
checksum = Digest::SHA512.digest(pw_bytes)
|
160
|
+
chs = hexlify(checksum)
|
161
|
+
# puts "chs", chs
|
162
|
+
# Create plain_data
|
163
|
+
keys = {@public_key => @private_key}
|
164
|
+
# puts "keys:", keys
|
165
|
+
plain_keys = {"checksum" => chs, "keys" => keys}
|
166
|
+
plain_data = JSON.dump(plain_keys)
|
167
|
+
# puts "plain_data:", plain_data
|
168
|
+
|
169
|
+
# Encrypt AES
|
170
|
+
msg_encrypt = encrypt(chs, plain_data)
|
171
|
+
msg_hex = hexlify(msg_encrypt)
|
172
|
+
# puts "msg_hex:", msg_hex
|
173
|
+
@cipher_keys = msg_hex
|
174
|
+
|
175
|
+
# Create data save.
|
176
|
+
wallet_data = {"cipher_keys" => @cipher_keys, "cipher_type" => @cipher_type, "salt" => @salt, "name" => @name}
|
177
|
+
wallet_json = JSON.dump(wallet_data)
|
178
|
+
wallet_json
|
179
|
+
end
|
180
|
+
|
145
181
|
# https://gist.github.com/andrekandore/3140554
|
146
182
|
def encrypt(key, data)
|
147
183
|
block = key[0..31]
|
@@ -202,6 +238,45 @@ module Beowulf
|
|
202
238
|
end
|
203
239
|
end
|
204
240
|
|
241
|
+
def decode_wallet(wallet_json_string, password)
|
242
|
+
# Validate inputs
|
243
|
+
if wallet_json_string == nil || wallet_json_string.length == 0
|
244
|
+
puts "Wallet json is not empty."
|
245
|
+
raise WalletError, "Wallet json is not empty."
|
246
|
+
end
|
247
|
+
wallet_json = JSON.parse(wallet_json_string)
|
248
|
+
# Init properties wallet
|
249
|
+
@name = wallet_json['name']
|
250
|
+
@cipher_keys = wallet_json['cipher_keys']
|
251
|
+
# puts "decode_wallet.cipher_keys:", @cipher_keys
|
252
|
+
@salt = wallet_json['salt']
|
253
|
+
# Create checksum
|
254
|
+
new_password = password + @salt
|
255
|
+
# puts "new_password:", new_password
|
256
|
+
pw_bytes = pakStr(new_password)
|
257
|
+
checksum = Digest::SHA512.digest(pw_bytes)
|
258
|
+
chs = hexlify(checksum)
|
259
|
+
# puts "chs", chs
|
260
|
+
# Decrypt data
|
261
|
+
data_byte = unhexlify(@cipher_keys)
|
262
|
+
# Decrypt AES
|
263
|
+
msg_decrypt = decrypt(chs, data_byte)
|
264
|
+
# puts "msg_decrypt:", msg_decrypt
|
265
|
+
msg_json = JSON.parse(msg_decrypt)
|
266
|
+
# puts "msg_json:", msg_json
|
267
|
+
dechs = msg_json['checksum']
|
268
|
+
if !(chs.eql? dechs)
|
269
|
+
puts "Password wrong."
|
270
|
+
raise WalletError, "Password wrong."
|
271
|
+
end
|
272
|
+
keys = msg_json['keys']
|
273
|
+
keys.each do |key, value|
|
274
|
+
# puts "#{key} is #{value}"
|
275
|
+
@public_key = key
|
276
|
+
@private_key = value
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
205
280
|
# https://gist.github.com/andrekandore/3140554
|
206
281
|
def decrypt(key, data)
|
207
282
|
block = key[0..31]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: beowulf-ruby-testnet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- NghiaTC
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-02-
|
11
|
+
date: 2020-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|