universa 3.14.2.2 → 3.14.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/universa/keytool/keytool.rb +38 -20
- data/lib/universa/text_objects.rb +22 -0
- data/lib/universa/version.rb +1 -1
- data/lib/universa.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45b80876f80d3a1d753ae95564492344a3949ed918cb74e4d76e039e5d9aa5bf
|
4
|
+
data.tar.gz: 7a091a3cd7d7e107619d8ae47a9b39a8b5c3c0a81646d6feb863f3c8722e1d1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3686641fdef17fa73cde3891352cea13ac73c7ef965e5fa63e4c087bfc100a9b266d71d0f70a446a9220e47dc88abfedeee52895de170087b33a820044393e16
|
7
|
+
data.tar.gz: 7fa8bf49efbdd6f4339d54e0e2bca6c15db375f7052cad7474fc312e0d506eb0012cf76d6e3adf2d3084ecc40160637e75041ea0b55870d208f7cee655f28977
|
@@ -6,8 +6,7 @@ require 'universa/tools'
|
|
6
6
|
|
7
7
|
include Universa
|
8
8
|
|
9
|
-
class MessageException < Exception;
|
10
|
-
end
|
9
|
+
class MessageException < Exception; end
|
11
10
|
|
12
11
|
def error message
|
13
12
|
raise MessageException, message
|
@@ -55,20 +54,20 @@ class KeyTool
|
|
55
54
|
def session_password
|
56
55
|
@require_password or return nil
|
57
56
|
@session_password ||= begin
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
57
|
+
if @autogenerate_password
|
58
|
+
psw = 29.random_alnums
|
59
|
+
puts "Autogenerated password: #{ANSI.bold { psw }}"
|
60
|
+
psw
|
61
|
+
else
|
62
|
+
puts "\nPlease enter password for key to be generated"
|
63
|
+
psw1 = STDIN.noecho(&:gets).chomp
|
64
|
+
puts "Please re-enter the password"
|
65
|
+
psw2 = STDIN.noecho(&:gets).chomp
|
66
|
+
psw1 == psw2 or error "passwords do not match"
|
67
|
+
psw1.length < 8 and error "password is too short"
|
68
|
+
psw1
|
69
|
+
end
|
70
|
+
end
|
72
71
|
end
|
73
72
|
|
74
73
|
def output_file(extension = nil, overwrite_existing_name = nil)
|
@@ -80,7 +79,7 @@ class KeyTool
|
|
80
79
|
extension && !name.end_with?(extension) ? "#{name}#{extension}" : name
|
81
80
|
end
|
82
81
|
|
83
|
-
def load_key(name)
|
82
|
+
def load_key(name, allow_public = false)
|
84
83
|
packed = open(name, 'rb') { |f| f.read } rescue error("can't read file: #{name}")
|
85
84
|
begin
|
86
85
|
PrivateKey.from_packed(packed)
|
@@ -94,8 +93,14 @@ class KeyTool
|
|
94
93
|
key = PrivateKey.from_packed(packed, password: password) rescue nil
|
95
94
|
key and break key
|
96
95
|
end
|
96
|
+
elsif allow_public
|
97
|
+
begin
|
98
|
+
PublicKey.from_packed(packed)
|
99
|
+
rescue
|
100
|
+
error "can't load the private/public key (file corrupt?)"
|
101
|
+
end
|
97
102
|
else
|
98
|
-
error "can't load the key (file corrupt?)"
|
103
|
+
error "can't load the private key (file corrupt?)"
|
99
104
|
end
|
100
105
|
end
|
101
106
|
end
|
@@ -178,11 +183,24 @@ class KeyTool
|
|
178
183
|
@rounds < 100000 and error "To few rounds, use at least 100000"
|
179
184
|
}
|
180
185
|
|
186
|
+
opts.on("-p FILE", "--public FILE", "extract public key") { |name|
|
187
|
+
task {
|
188
|
+
key = load_key(name, true)
|
189
|
+
if @output_file
|
190
|
+
open(output_file(".public.unikey"), 'wb') { |f| f << key.pack() }
|
191
|
+
else
|
192
|
+
puts format_text_object(key.pack(), "public key", fileName: name)
|
193
|
+
# puts "not yet implemented #{key.long_address.to_s}"
|
194
|
+
end
|
195
|
+
}
|
196
|
+
}
|
197
|
+
|
181
198
|
opts.on("-s FILE", "--show FILE", "show key information") { |name|
|
182
199
|
task {
|
183
|
-
key = load_key(name)
|
200
|
+
key = load_key(name, true)
|
201
|
+
is_private = key.is_a? PrivateKey
|
184
202
|
puts "\r----------------------------------------------------------------------------------------"
|
185
|
-
puts "Private key, #{key.info.getKeyLength() * 8} bits\n"
|
203
|
+
puts "#{is_private ? 'Private' : 'Public'} key, #{key.info.getKeyLength() * 8} bits\n"
|
186
204
|
puts "Short address : #{ANSI.bold { key.short_address.to_s }}"
|
187
205
|
puts "Long address : #{ANSI.bold { key.long_address.to_s }}"
|
188
206
|
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'digest'
|
2
|
+
|
3
|
+
# Generate universa text object representation from arbitrary data, see
|
4
|
+
# https://kb.universablockchain.com/text_format_for_universa_objects/311
|
5
|
+
# for details.
|
6
|
+
#
|
7
|
+
# @param [Object] data binary string to pack as universa text object
|
8
|
+
# @param [Object] type object type, see link above
|
9
|
+
# @param [Hash] kwargs any additional fields
|
10
|
+
# @return [String] string with properly framed universa object
|
11
|
+
def format_text_object(data, type, **kwargs)
|
12
|
+
source = ["type: #{type}"]
|
13
|
+
kwargs.each { |k, v|
|
14
|
+
source << "#{k}: #{v}"
|
15
|
+
}
|
16
|
+
source << ""
|
17
|
+
source << Base64.encode64(data)
|
18
|
+
hash = Digest::SHA2.base64digest(source.join(''))
|
19
|
+
"==== Begin Universa Object: #{hash} ====\n" +
|
20
|
+
source.join("\n") +
|
21
|
+
"\n===== End Universa Object: #{hash} =====\n"
|
22
|
+
end
|
data/lib/universa/version.rb
CHANGED
data/lib/universa.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: universa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.14.2.
|
4
|
+
version: 3.14.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sergeych
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: farcall
|
@@ -174,6 +174,7 @@ files:
|
|
174
174
|
- lib/universa/service.rb
|
175
175
|
- lib/universa/stored_contract.rb
|
176
176
|
- lib/universa/string_utils.rb
|
177
|
+
- lib/universa/text_objects.rb
|
177
178
|
- lib/universa/tools.rb
|
178
179
|
- lib/universa/u_settings.rb
|
179
180
|
- lib/universa/ubox.rb
|
@@ -204,7 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
204
205
|
- !ruby/object:Gem::Version
|
205
206
|
version: '0'
|
206
207
|
requirements: []
|
207
|
-
rubygems_version: 3.2.
|
208
|
+
rubygems_version: 3.2.22
|
208
209
|
signing_key:
|
209
210
|
specification_version: 4
|
210
211
|
summary: Expose Universa Java API to ruby
|