universa 3.14.2.2 → 3.14.2.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6487e468be6041ca989e00499911941b71f8684fcdf171e9659c3934f26a54f8
4
- data.tar.gz: 0e04d054937e42a0955a48597fc20766327b2438d036c490d4dbe12b79d86ae5
3
+ metadata.gz: 45b80876f80d3a1d753ae95564492344a3949ed918cb74e4d76e039e5d9aa5bf
4
+ data.tar.gz: 7a091a3cd7d7e107619d8ae47a9b39a8b5c3c0a81646d6feb863f3c8722e1d1b
5
5
  SHA512:
6
- metadata.gz: 3106d98aa41169ff04865fcf6b21705077f0d365ac9064cb577b8a5e68af6aafc8086999f10d2da3e5641e8f0e59d839fa68011a9ff4acfb18c44c8c7197ad36
7
- data.tar.gz: f5be6b114d0df7d4e625c6b8c4a4a7a2469105c10f8fe9fcba1d792e8f361a4827040956ddb1ca2bbc9fb771027d19c83d5873daf32ba4d0cf8e22eead6475b4
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
- if @autogenerate_password
59
- psw = 29.random_alnums
60
- puts "Autogenerated password: #{ANSI.bold { psw }}"
61
- psw
62
- else
63
- puts "\nPlease enter password for key to be generated"
64
- psw1 = STDIN.noecho(&:gets).chomp
65
- puts "Please re-enter the password"
66
- psw2 = STDIN.noecho(&:gets).chomp
67
- psw1 == psw2 or error "passwords do not match"
68
- psw1.length < 8 and error "password is too short"
69
- psw1
70
- end
71
- end
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
@@ -1,4 +1,4 @@
1
1
  module Universa
2
2
  # Current gem version
3
- VERSION = "3.14.2.2"
3
+ VERSION = "3.14.2.4"
4
4
  end
data/lib/universa.rb CHANGED
@@ -12,6 +12,7 @@ require 'universa/stored_contract'
12
12
  require "universa/chain_store"
13
13
  require "universa/universa_helpers"
14
14
  require "universa/fs_store/file_store"
15
+ require "universa/text_objects"
15
16
 
16
17
  # The Universa gem
17
18
  #
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.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-09-21 00:00:00.000000000 Z
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.15
208
+ rubygems_version: 3.2.22
208
209
  signing_key:
209
210
  specification_version: 4
210
211
  summary: Expose Universa Java API to ruby