universa 3.13.2.1 → 3.14.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +22 -6
  3. data/bin/refresh_umi +1 -1
  4. data/bin/umi/bin/umi +4 -4
  5. data/bin/umi/bin/umi.bat +1 -1
  6. data/bin/umi/lib/{com.icodici.common_tools-3.13.2.jar → com.icodici.common_tools-3.14.2.jar} +0 -0
  7. data/bin/umi/lib/{com.icodici.crypto-3.13.2.jar → com.icodici.crypto-3.14.2.jar} +0 -0
  8. data/bin/umi/lib/com.icodici.umi-0.8.72.jar +0 -0
  9. data/bin/umi/lib/com.icodici.universa_core-3.14.2.jar +0 -0
  10. data/lib/universa/binder.rb +5 -5
  11. data/lib/universa/contract.rb +29 -3
  12. data/lib/universa/dump.rb +40 -0
  13. data/lib/universa/keytool/keytool.rb +38 -20
  14. data/lib/universa/service.rb +15 -6
  15. data/lib/universa/text_objects.rb +22 -0
  16. data/lib/universa/umi.rb +1 -1
  17. data/lib/universa/version.rb +1 -1
  18. data/lib/universa.rb +1 -0
  19. data/samples/load_contract.rb +10 -0
  20. data/samples/safe58_sample.rb +45 -0
  21. data/universa.gemspec +2 -2
  22. metadata +19 -25
  23. data/bin/umi/lib/com.fasterxml.jackson.core.jackson-annotations-2.8.11.jar +0 -0
  24. data/bin/umi/lib/com.fasterxml.jackson.core.jackson-core-2.8.11.jar +0 -0
  25. data/bin/umi/lib/com.fasterxml.jackson.core.jackson-databind-2.8.11.1.jar +0 -0
  26. data/bin/umi/lib/com.fasterxml.jackson.datatype.jackson-datatype-jdk8-2.8.11.jar +0 -0
  27. data/bin/umi/lib/com.fasterxml.jackson.datatype.jackson-datatype-jsr310-2.8.11.jar +0 -0
  28. data/bin/umi/lib/com.icodici.umi-0.8.67.jar +0 -0
  29. data/bin/umi/lib/com.icodici.universa_core-3.13.2.jar +0 -0
  30. data/bin/umi/lib/com.typesafe.play.play-functional_2.12-2.6.10.jar +0 -0
  31. data/bin/umi/lib/com.typesafe.play.play-json_2.12-2.6.10.jar +0 -0
  32. data/bin/umi/lib/joda-time.joda-time-2.9.9.jar +0 -0
  33. data/bin/umi/lib/org.scala-lang.scala-reflect-2.12.7.jar +0 -0
  34. data/bin/umi/lib/org.typelevel.macro-compat_2.12-1.1.1.jar +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e864fbf25b814e9064d7d0148e22b9eab669099ad92d4cd5672e1e0127e0ddaf
4
- data.tar.gz: 6c7250174e5d4917e8f360e4e2c449af618a2abb7e39fabea9b29cf19f61ecab
3
+ metadata.gz: 45b80876f80d3a1d753ae95564492344a3949ed918cb74e4d76e039e5d9aa5bf
4
+ data.tar.gz: 7a091a3cd7d7e107619d8ae47a9b39a8b5c3c0a81646d6feb863f3c8722e1d1b
5
5
  SHA512:
6
- metadata.gz: 3fc5362eaeae51fb132a55062d6c91378454bbafdba70f3dbfcd7982635d7a79b4908c1f127145a27ee425b24bf819415f9cb37ae0d51d1e4cce16339cb84a65
7
- data.tar.gz: 0d92f08da7fffcc0ae392d6efd7c69ac1f9553c8acffe52ddb623c8e5f4d7a48109d5f8a197eede2fcd9e46e152b0567af08db60b34c58b7057f0a1ac0328288
6
+ metadata.gz: 3686641fdef17fa73cde3891352cea13ac73c7ef965e5fa63e4c087bfc100a9b266d71d0f70a446a9220e47dc88abfedeee52895de170087b33a820044393e16
7
+ data.tar.gz: 7fa8bf49efbdd6f4339d54e0e2bca6c15db375f7052cad7474fc312e0d506eb0012cf76d6e3adf2d3084ecc40160637e75041ea0b55870d208f7cee655f28977
data/README.md CHANGED
@@ -1,15 +1,11 @@
1
1
  # Universa
2
2
 
3
- > beta state: direct full access to Java API ready for test, started adapter of remote objects - syntax sugar
4
- for direct access to remote objects.
5
-
6
- __attention__ since this release version numbers match the Universa Core library version included.
7
-
8
3
  This is an under-construction official gem from [Universa][universa] to facilitate access to the
9
- Java library using Universa's UMI protocol and Universa client services.
4
+ Java library using Universa UMI protocol and Universa client services.
10
5
 
11
6
  ## News
12
7
 
8
+ - production-tested in various universa projects
13
9
  - rewritten Client and Connection to use new consensus-based, dns-free Universa network topology discovery protocol
14
10
  - added syntax sugar for TransactionPack
15
11
  - alfa version of the local FS-based contract store.
@@ -46,6 +42,26 @@ Or install it yourself as:
46
42
 
47
43
  ## Usage
48
44
 
45
+ ### Direct access to Universa objects:
46
+
47
+ ~~~ruby
48
+ include Universa
49
+
50
+ @private_key = PrivateKey.new 2048
51
+ c = Contract.create @private_key
52
+ c.get_creator.get_all_addresses.should == [@private_key.long_address.to_s]
53
+ c.seal()
54
+ c.check() and c.trace_errors()
55
+ c.should be_ok
56
+
57
+ c1 = Contract.from_packed(c.packed)
58
+ c1.hash_id.should == c.hash_id
59
+ c1.should == c
60
+ c1.expires_at.should > (Time.now + 120)
61
+ ~~~
62
+
63
+ see smaples in specs (spec/contract_spec, spec/compound_spec, etc.)
64
+
49
65
  ### Direct access to UMI
50
66
 
51
67
  So far, you can only get direct access the the Java API functions. To get it:
data/bin/refresh_umi CHANGED
@@ -16,5 +16,5 @@ rm -rd ./bin/__MACOSX >/dev/null 2>&1
16
16
 
17
17
  rm download
18
18
 
19
- echo "successfully nstalled version: `bin/umi/bin/umi --version`"
19
+ echo "successfully installed version: `bin/umi/bin/umi --version`"
20
20
 
data/bin/umi/bin/umi CHANGED
@@ -267,7 +267,7 @@ loadConfigFile() {
267
267
  }
268
268
 
269
269
  # Now check to see if it's a good enough version
270
- # TODO - Check to see if we have a configured default java version, otherwise use 1.6
270
+ # TODO - Check to see if we have a configured default java version, otherwise use 1.8
271
271
  java_version_check() {
272
272
  readonly java_version=$("$java_cmd" -version 2>&1 | awk -F '"' '/version/ {print $2}')
273
273
  if [[ "$java_version" == "" ]]; then
@@ -281,10 +281,10 @@ java_version_check() {
281
281
  if [[ "$major" -eq "1" ]]; then
282
282
  local major=$(echo "$java_version" | cut -d'.' -f2)
283
283
  fi
284
- if [[ "$major" -lt "6" ]]; then
284
+ if [[ "$major" -lt "8" ]]; then
285
285
  echo
286
286
  echo The java installation you have is not up to date
287
- echo $app_name requires at least version 1.6+, you have
287
+ echo $app_name requires at least version 1.8+, you have
288
288
  echo version $java_version
289
289
  echo
290
290
  echo Please go to http://www.java.com/getjava/ and download
@@ -344,7 +344,7 @@ declare -r lib_dir="$(realpath "${app_home}/../lib")"
344
344
  declare -a app_mainclass=(com.icodici.farcallscala.Main)
345
345
 
346
346
  declare -r script_conf_file="${app_home}/../conf/application.ini"
347
- declare -r app_classpath="$lib_dir/com.icodici.umi-0.8.67.jar:$lib_dir/org.scala-lang.scala-library-2.12.7.jar:$lib_dir/com.icodici.universa_core-3.13.2.jar:$lib_dir/org.yaml.snakeyaml-1.18.jar:$lib_dir/com.icodici.nanohttpd-2.1.0.jar:$lib_dir/com.icodici.common_tools-3.13.2.jar:$lib_dir/com.eclipsesource.minimal-json.minimal-json-0.9.4.jar:$lib_dir/net.java.dev.jna.jna-4.5.1.jar:$lib_dir/org.checkerframework.checker-qual-2.3.2.jar:$lib_dir/com.icodici.crypto-3.13.2.jar:$lib_dir/org.bouncycastle.bcprov-jdk15on-1.62.jar:$lib_dir/com.squareup.jnagmp.jnagmp-2.0.0.jar:$lib_dir/com.typesafe.play.play-json_2.12-2.6.10.jar:$lib_dir/com.typesafe.play.play-functional_2.12-2.6.10.jar:$lib_dir/org.scala-lang.scala-reflect-2.12.7.jar:$lib_dir/org.typelevel.macro-compat_2.12-1.1.1.jar:$lib_dir/joda-time.joda-time-2.9.9.jar:$lib_dir/com.fasterxml.jackson.core.jackson-core-2.8.11.jar:$lib_dir/com.fasterxml.jackson.core.jackson-annotations-2.8.11.jar:$lib_dir/com.fasterxml.jackson.datatype.jackson-datatype-jdk8-2.8.11.jar:$lib_dir/com.fasterxml.jackson.core.jackson-databind-2.8.11.1.jar:$lib_dir/com.fasterxml.jackson.datatype.jackson-datatype-jsr310-2.8.11.jar:$lib_dir/org.scala-sbt.ipcsocket.ipcsocket-1.0.0.jar:$lib_dir/net.java.dev.jna.jna-platform-4.5.0.jar:$lib_dir/net.sf.jopt-simple.jopt-simple-4.9.jar"
347
+ declare -r app_classpath="$lib_dir/com.icodici.umi-0.8.72.jar:$lib_dir/org.scala-lang.scala-library-2.12.7.jar:$lib_dir/com.icodici.universa_core-3.14.2.jar:$lib_dir/org.yaml.snakeyaml-1.18.jar:$lib_dir/com.icodici.nanohttpd-2.1.0.jar:$lib_dir/com.icodici.common_tools-3.14.2.jar:$lib_dir/com.eclipsesource.minimal-json.minimal-json-0.9.4.jar:$lib_dir/net.java.dev.jna.jna-4.5.1.jar:$lib_dir/org.checkerframework.checker-qual-2.3.2.jar:$lib_dir/com.icodici.crypto-3.14.2.jar:$lib_dir/org.bouncycastle.bcprov-jdk15on-1.62.jar:$lib_dir/com.squareup.jnagmp.jnagmp-2.0.0.jar:$lib_dir/org.scala-sbt.ipcsocket.ipcsocket-1.0.0.jar:$lib_dir/net.java.dev.jna.jna-platform-4.5.0.jar:$lib_dir/net.sf.jopt-simple.jopt-simple-4.9.jar"
348
348
 
349
349
  # java_cmd is overrode in process_args when -java-home is used
350
350
  declare java_cmd=$(get_java_cmd)
data/bin/umi/bin/umi.bat CHANGED
@@ -80,7 +80,7 @@ rem "-J" is stripped, "-D" is left as is, and everything is appended to JAVA_OPT
80
80
  set _JAVA_PARAMS=
81
81
  set _APP_ARGS=
82
82
 
83
- set "APP_CLASSPATH=%APP_LIB_DIR%\com.icodici.umi-0.8.67.jar;%APP_LIB_DIR%\org.scala-lang.scala-library-2.12.7.jar;%APP_LIB_DIR%\com.icodici.universa_core-3.13.2.jar;%APP_LIB_DIR%\org.yaml.snakeyaml-1.18.jar;%APP_LIB_DIR%\com.icodici.nanohttpd-2.1.0.jar;%APP_LIB_DIR%\com.icodici.common_tools-3.13.2.jar;%APP_LIB_DIR%\com.eclipsesource.minimal-json.minimal-json-0.9.4.jar;%APP_LIB_DIR%\net.java.dev.jna.jna-4.5.1.jar;%APP_LIB_DIR%\org.checkerframework.checker-qual-2.3.2.jar;%APP_LIB_DIR%\com.icodici.crypto-3.13.2.jar;%APP_LIB_DIR%\org.bouncycastle.bcprov-jdk15on-1.62.jar;%APP_LIB_DIR%\com.squareup.jnagmp.jnagmp-2.0.0.jar;%APP_LIB_DIR%\com.typesafe.play.play-json_2.12-2.6.10.jar;%APP_LIB_DIR%\com.typesafe.play.play-functional_2.12-2.6.10.jar;%APP_LIB_DIR%\org.scala-lang.scala-reflect-2.12.7.jar;%APP_LIB_DIR%\org.typelevel.macro-compat_2.12-1.1.1.jar;%APP_LIB_DIR%\joda-time.joda-time-2.9.9.jar;%APP_LIB_DIR%\com.fasterxml.jackson.core.jackson-core-2.8.11.jar;%APP_LIB_DIR%\com.fasterxml.jackson.core.jackson-annotations-2.8.11.jar;%APP_LIB_DIR%\com.fasterxml.jackson.datatype.jackson-datatype-jdk8-2.8.11.jar;%APP_LIB_DIR%\com.fasterxml.jackson.core.jackson-databind-2.8.11.1.jar;%APP_LIB_DIR%\com.fasterxml.jackson.datatype.jackson-datatype-jsr310-2.8.11.jar;%APP_LIB_DIR%\org.scala-sbt.ipcsocket.ipcsocket-1.0.0.jar;%APP_LIB_DIR%\net.java.dev.jna.jna-platform-4.5.0.jar;%APP_LIB_DIR%\net.sf.jopt-simple.jopt-simple-4.9.jar"
83
+ set "APP_CLASSPATH=%APP_LIB_DIR%\com.icodici.umi-0.8.72.jar;%APP_LIB_DIR%\org.scala-lang.scala-library-2.12.7.jar;%APP_LIB_DIR%\com.icodici.universa_core-3.14.2.jar;%APP_LIB_DIR%\org.yaml.snakeyaml-1.18.jar;%APP_LIB_DIR%\com.icodici.nanohttpd-2.1.0.jar;%APP_LIB_DIR%\com.icodici.common_tools-3.14.2.jar;%APP_LIB_DIR%\com.eclipsesource.minimal-json.minimal-json-0.9.4.jar;%APP_LIB_DIR%\net.java.dev.jna.jna-4.5.1.jar;%APP_LIB_DIR%\org.checkerframework.checker-qual-2.3.2.jar;%APP_LIB_DIR%\com.icodici.crypto-3.14.2.jar;%APP_LIB_DIR%\org.bouncycastle.bcprov-jdk15on-1.62.jar;%APP_LIB_DIR%\com.squareup.jnagmp.jnagmp-2.0.0.jar;%APP_LIB_DIR%\org.scala-sbt.ipcsocket.ipcsocket-1.0.0.jar;%APP_LIB_DIR%\net.java.dev.jna.jna-platform-4.5.0.jar;%APP_LIB_DIR%\net.sf.jopt-simple.jopt-simple-4.9.jar"
84
84
  set "APP_MAIN_CLASS=com.icodici.farcallscala.Main"
85
85
  set "SCRIPT_CONF_FILE=%APP_HOME%\conf\application.ini"
86
86
 
@@ -29,6 +29,10 @@ module Universa
29
29
  __getobj__.keySet()
30
30
  end
31
31
 
32
+ def binary(key)
33
+ __getobj__.getBinary(key)
34
+ end
35
+
32
36
  # # Internal use only. Allow processing remote commands as local calls
33
37
  def respond_to_missing?(method_name, include_private = false)
34
38
  l = method_name[-1]
@@ -57,6 +61,7 @@ module Universa
57
61
  end
58
62
 
59
63
  # Converts binder to the array of [key, value] pairs, like with regular ruby hashes
64
+ # @return [Array(Array(String,Object))] array of [key,value] pairs.
60
65
  def to_a
61
66
  map {|x| x}
62
67
  end
@@ -73,11 +78,6 @@ module Universa
73
78
  keys.map {|k| block.call [k, __getobj__.get(k)]}
74
79
  end
75
80
 
76
- # @return [Array(Array(String,Object))] array of [key,value] pairs.
77
- def to_a
78
- map {|x| x}
79
- end
80
-
81
81
  # converts to a regular ruby hash
82
82
  def to_h
83
83
  to_a.to_h
@@ -35,6 +35,15 @@ module Universa
35
35
  end
36
36
  end
37
37
 
38
+ # Safe58 allows human-friendly binary-to-characters codec. It automatically corrects recognition
39
+ # errors like 0 instead of 0 and 1 instead of I. The code does not use characters that look alike and
40
+ # uses only encglish letters and digits that also simplify select-copy-paste routine.
41
+ #
42
+ # important! arguments MUST be binary strings, so use
43
+ #
44
+ # str.force_encoding('binary')
45
+ #
46
+ # as need, otherwise it will not work as expected.
38
47
  class Safe58 < RemoteAdapter
39
48
  remote_class "net.sergeych.utils.Safe58"
40
49
 
@@ -58,6 +67,11 @@ module Universa
58
67
  remote_class "com.icodici.universa.contract.permissions.ChangeOwnerPermission"
59
68
  end
60
69
 
70
+ # Adapter for Universa ChangeRolePermission
71
+ class ChangeRolePermission < RemoteAdapter
72
+ remote_class "com.icodici.universa.contract.permissions.ChangeRolePermission"
73
+ end
74
+
61
75
  # Adapter for Universa RevokePermission
62
76
  class RevokePermission < RemoteAdapter
63
77
  remote_class "com.icodici.universa.contract.permissions.RevokePermission"
@@ -91,6 +105,10 @@ module Universa
91
105
  # adapter for a role that is a list of roles
92
106
  class ListRole < RemoteAdapter
93
107
  remote_class "com.icodici.universa.contract.roles.ListRole"
108
+
109
+ class Mode
110
+ ANY = 'ANY'
111
+ end
94
112
  end
95
113
 
96
114
  # Adapter for permission to modify data
@@ -98,6 +116,10 @@ module Universa
98
116
  remote_class "com.icodici.universa.contract.permissions.ModifyDataPermission"
99
117
  end
100
118
 
119
+ # Adapter for Universa QuorumVoteRole
120
+ class QuorumVoteRole < RemoteAdapter
121
+ remote_class "com.icodici.universa.contract.roles.QuorumVoteRole"
122
+ end
101
123
 
102
124
  # Wrapper for Java API Reference class
103
125
 
@@ -240,7 +262,7 @@ module Universa
240
262
  # @return [Contract] simple contact, not sealed
241
263
  def self.create issuer_key, expires_at: (Time.now + 90 * 24 * 60 * 60), use_short_address: false
242
264
  contract = Contract.new
243
- contract.set_expires_at expires_at
265
+ contract.set_expires_at expires_at.utc
244
266
  contract.set_issuer_keys(use_short_address ? issuer_key.short_address : issuer_key.long_address)
245
267
  contract.register_role(contract.issuer.link_as("owner"))
246
268
  contract.register_role(contract.issuer.link_as("creator"))
@@ -320,7 +342,7 @@ module Universa
320
342
  # set +expires_at+ field
321
343
  # @param [Time] time when this contract will be expired, if yet +APPROVED+.
322
344
  def expires_at=(time)
323
- set_expires_at time
345
+ set_expires_at time.utc
324
346
  end
325
347
 
326
348
  # @return definition data
@@ -408,4 +430,8 @@ module Universa
408
430
  end
409
431
  end
410
432
 
411
- end
433
+ class ExtendedSignature < RemoteAdapter
434
+ remote_class "com.icodici.universa.contract.ExtendedSignature"
435
+ end
436
+
437
+ end
@@ -0,0 +1,40 @@
1
+ module Universa
2
+
3
+ # Convert binary data to a human-readable dump string, like
4
+ #
5
+ # <code>
6
+ # 000000 27 23 64 61 74 61 c4 2d 0f |'#data.-.|
7
+ # 000008 0f 1f 43 63 6f 6e 74 72 61 |..Ccontra|
8
+ # </code>
9
+ #
10
+ # @param data[String] data to dump
11
+ # @param line_bytes[Number] how many bytes to show in each line
12
+ # @return [String] dump as a string
13
+ def dump_bytes data, line_bytes=16
14
+ data.force_encoding Encoding::BINARY
15
+ offset = 0
16
+ res = []
17
+
18
+ while( offset < data.length )
19
+
20
+ left = "%06x" % offset
21
+ portion = data[offset..(offset+line_bytes)].bytes
22
+
23
+ bytes = portion.map { |x| "%02x" % x }.join(' ')
24
+ chars = portion.map { |c| x = c.ord; x >= 32 && x <= 'z'.ord ? x.chr : '.' }.join('')
25
+
26
+ if chars.length < line_bytes
27
+ pad = line_bytes - chars.length + 1
28
+ chars += ' ' * pad
29
+ bytes += ' ' * pad
30
+ end
31
+
32
+ res << "#{left} #{bytes} |#{chars}|"
33
+
34
+ offset += line_bytes
35
+ end
36
+ res.join("\n")
37
+ end
38
+
39
+ module_function :dump_bytes
40
+ end
@@ -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
  }
@@ -2,7 +2,7 @@ require 'singleton'
2
2
 
3
3
  module Universa
4
4
 
5
- # The service is a singleton to provide porcess-wide objects and methods. For example,
5
+ # The service is a singleton to provide process-wide objects and methods. For example,
6
6
  # the {UMI} interface and reference class factory are unique per-process for Universa
7
7
  # library. It uses exactly one lazy created {UMI} connection which is shared among all threads.
8
8
  # As UMI server is multithreaded by nature, is will not block ruby threads waiting for remote
@@ -26,7 +26,8 @@ module Universa
26
26
  @known_proxies = {}
27
27
  [Contract, PrivateKey, PublicKey, KeyAddress, HashId, Binder,
28
28
  Role, SimpleRole, RoleLink, ListRole, Parcel, UnsContract,
29
- ChangeOwnerPermission, RevokePermission, ModifyDataPermission, SplitJoinPermission,
29
+ ChangeOwnerPermission, ChangeRolePermission, RevokePermission,
30
+ ModifyDataPermission, SplitJoinPermission, QuorumVoteRole,
30
31
  UmiClient, Duration, Compound, KeyInfo, PBKDF2].each {|klass| register_proxy klass}
31
32
  end
32
33
 
@@ -66,11 +67,19 @@ module Universa
66
67
  instance.configure &block
67
68
  end
68
69
 
70
+
69
71
  # Get the global UMI interface, creating it if need.
70
72
  # @return [UMI] ready interface
71
73
  def umi
72
- instance.umi
74
+ @@instance_lock.synchronize {
75
+ instance.umi
76
+ }
73
77
  end
78
+
79
+ private
80
+
81
+ @@instance_lock = Monitor.new
82
+
74
83
  end
75
84
 
76
85
  # Register a class that will work as a proxy for UMI remote class. Such adapter class mist extend RemoteAdapter
@@ -120,7 +129,7 @@ module Universa
120
129
 
121
130
  # Updating proxied object is not allowed. Raises error.
122
131
  def __setobj__
123
- raise "ObectProxy does not support changing referenced object"
132
+ raise "ObjectProxy does not support changing referenced object"
124
133
  end
125
134
 
126
135
  # Returns remote class name. There is no need to override it, when inheriting it use +remote_class+ helper:
@@ -131,11 +140,11 @@ module Universa
131
140
  # #...
132
141
  # end
133
142
  #
134
- # Notice: remote_class will do allnecessary work for you.
143
+ # Notice: remote_class will do all necessary work for you.
135
144
  #
136
145
  # @return [String] remote class name
137
146
  def self.remote_class_name
138
- @remote_class_name or raise Error, "provde remote class name"
147
+ @remote_class_name or raise Error, "provide remote class name"
139
148
  end
140
149
 
141
150
  # Registers remote class name to be used with this adapted. Call it early in descendant class
@@ -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/umi.rb CHANGED
@@ -372,7 +372,7 @@ module Universa
372
372
  # Java classes, whose references are created on-the-fly automatically (and will be reclaimed by GC on both
373
373
  # ends soon).
374
374
  #
375
- # == Instances are uniqie
375
+ # == Instances are unique
376
376
  #
377
377
  # What means, if some calls will return the same Java object instance, it will be returned as the same {Ref}
378
378
  # instance.
@@ -1,4 +1,4 @@
1
1
  module Universa
2
2
  # Current gem version
3
- VERSION = "3.13.2.1"
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
  #
@@ -0,0 +1,10 @@
1
+ require_relative '../lib/universa/dump'
2
+
3
+ source_file = ARGV[0] || File.expand_path("~/Downloads/c.unicon")
4
+
5
+ packed = open(source_file,'rb') { |f| f.read }
6
+
7
+ puts Universa::dump_bytes(packed)
8
+
9
+ require 'base64'
10
+ puts Base64.encode64(packed)
@@ -0,0 +1,45 @@
1
+ # example:
2
+ #
3
+ # rationale:
4
+ # We want to pass order code to user which is potentially long integer (sam, above 9 characters in decimal
5
+ # notation), but the bank insist oreder code in the payment purpose should be 5-8 characters.
6
+ #
7
+ # solution:
8
+ #
9
+ # pack long id (we assume it will fit 5 bytes that give us >60 billions which is usually more
10
+ # than enough) to short and easy to human-retype code using SAFE58 encoding by Universa.
11
+ #
12
+ # It will nirmally give us 6 letter-code which is well protected against recognition mistakes,
13
+ # for example 0 instead of o or 1 instead of I or i. It autocorrects it and does not use like characters.
14
+ #
15
+ require 'universa'
16
+
17
+ # sample long to encode, 12 billions+ (12`884`901`887)
18
+ id = 0x2FFFFffff
19
+
20
+ def int_to_safe58(value)
21
+ # pack to BE 8-byte long
22
+ packed = [value].pack("Q>")
23
+
24
+ # important: safe58 needs binary encoded string, but pack already gives us binary string,
25
+ # so we strip 3 first bytes which are are zeroes and encode the rest to safe 58:
26
+ Universa::Safe58.encode(packed[3..])
27
+ end
28
+
29
+ def safe58_to_int(encoded)
30
+ # decode 5 bytes
31
+ bytes = Universa::Safe58.decode(encoded)
32
+ # pad left with 3 zero bytes to get back 64 bit integer and unpack it:
33
+ "\x0\x0\x0#{bytes}".unpack("Q>")[0]
34
+ end
35
+
36
+ puts "Encoded: #{id} -> #{int_to_safe58 id}"
37
+
38
+ id2 = safe58_to_int(int_to_safe58(id))
39
+ puts "Decoded: #{int_to_safe58 id} -> #{id2}"
40
+
41
+ id == id2 or raise "test failed"
42
+
43
+ puts "ALL OK"
44
+
45
+
data/universa.gemspec CHANGED
@@ -36,7 +36,7 @@ Gem::Specification.new do |spec|
36
36
  spec.add_dependency "concurrent-ruby-ext"
37
37
  spec.add_dependency "ansi"
38
38
 
39
- spec.add_development_dependency "bundler", "~> 1.16"
40
- spec.add_development_dependency "rake", "~> 10.0"
39
+ spec.add_development_dependency "bundler", "~> 2"
40
+ spec.add_development_dependency "rake", "~> 12.3.3"
41
41
  spec.add_development_dependency "rspec", "~> 3.8"
42
42
  end
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.13.2.1
4
+ version: 3.14.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - sergeych
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-04 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
@@ -86,28 +86,28 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '1.16'
89
+ version: '2'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '1.16'
96
+ version: '2'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rake
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '10.0'
103
+ version: 12.3.3
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '10.0'
110
+ version: 12.3.3
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rspec
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -144,29 +144,19 @@ files:
144
144
  - bin/umi/bin/umi
145
145
  - bin/umi/bin/umi.bat
146
146
  - bin/umi/lib/com.eclipsesource.minimal-json.minimal-json-0.9.4.jar
147
- - bin/umi/lib/com.fasterxml.jackson.core.jackson-annotations-2.8.11.jar
148
- - bin/umi/lib/com.fasterxml.jackson.core.jackson-core-2.8.11.jar
149
- - bin/umi/lib/com.fasterxml.jackson.core.jackson-databind-2.8.11.1.jar
150
- - bin/umi/lib/com.fasterxml.jackson.datatype.jackson-datatype-jdk8-2.8.11.jar
151
- - bin/umi/lib/com.fasterxml.jackson.datatype.jackson-datatype-jsr310-2.8.11.jar
152
- - bin/umi/lib/com.icodici.common_tools-3.13.2.jar
153
- - bin/umi/lib/com.icodici.crypto-3.13.2.jar
147
+ - bin/umi/lib/com.icodici.common_tools-3.14.2.jar
148
+ - bin/umi/lib/com.icodici.crypto-3.14.2.jar
154
149
  - bin/umi/lib/com.icodici.nanohttpd-2.1.0.jar
155
- - bin/umi/lib/com.icodici.umi-0.8.67.jar
156
- - bin/umi/lib/com.icodici.universa_core-3.13.2.jar
150
+ - bin/umi/lib/com.icodici.umi-0.8.72.jar
151
+ - bin/umi/lib/com.icodici.universa_core-3.14.2.jar
157
152
  - bin/umi/lib/com.squareup.jnagmp.jnagmp-2.0.0.jar
158
- - bin/umi/lib/com.typesafe.play.play-functional_2.12-2.6.10.jar
159
- - bin/umi/lib/com.typesafe.play.play-json_2.12-2.6.10.jar
160
- - bin/umi/lib/joda-time.joda-time-2.9.9.jar
161
153
  - bin/umi/lib/net.java.dev.jna.jna-4.5.1.jar
162
154
  - bin/umi/lib/net.java.dev.jna.jna-platform-4.5.0.jar
163
155
  - bin/umi/lib/net.sf.jopt-simple.jopt-simple-4.9.jar
164
156
  - bin/umi/lib/org.bouncycastle.bcprov-jdk15on-1.62.jar
165
157
  - bin/umi/lib/org.checkerframework.checker-qual-2.3.2.jar
166
158
  - bin/umi/lib/org.scala-lang.scala-library-2.12.7.jar
167
- - bin/umi/lib/org.scala-lang.scala-reflect-2.12.7.jar
168
159
  - bin/umi/lib/org.scala-sbt.ipcsocket.ipcsocket-1.0.0.jar
169
- - bin/umi/lib/org.typelevel.macro-compat_2.12-1.1.1.jar
170
160
  - bin/umi/lib/org.yaml.snakeyaml-1.18.jar
171
161
  - exe/unikeys
172
162
  - lib/universa.rb
@@ -174,6 +164,7 @@ files:
174
164
  - lib/universa/chain_store.rb
175
165
  - lib/universa/client.rb
176
166
  - lib/universa/contract.rb
167
+ - lib/universa/dump.rb
177
168
  - lib/universa/errors.rb
178
169
  - lib/universa/fs_store/entry.rb
179
170
  - lib/universa/fs_store/file_store.rb
@@ -183,6 +174,7 @@ files:
183
174
  - lib/universa/service.rb
184
175
  - lib/universa/stored_contract.rb
185
176
  - lib/universa/string_utils.rb
177
+ - lib/universa/text_objects.rb
186
178
  - lib/universa/tools.rb
187
179
  - lib/universa/u_settings.rb
188
180
  - lib/universa/ubox.rb
@@ -191,12 +183,14 @@ files:
191
183
  - lib/universa/version.rb
192
184
  - lib/universa/weak_reference.rb
193
185
  - sample_ping.rb
186
+ - samples/load_contract.rb
187
+ - samples/safe58_sample.rb
194
188
  - universa.gemspec
195
- homepage:
189
+ homepage:
196
190
  licenses:
197
191
  - MIT
198
192
  metadata: {}
199
- post_install_message:
193
+ post_install_message:
200
194
  rdoc_options: []
201
195
  require_paths:
202
196
  - lib
@@ -211,8 +205,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
211
205
  - !ruby/object:Gem::Version
212
206
  version: '0'
213
207
  requirements: []
214
- rubygems_version: 3.0.3
215
- signing_key:
208
+ rubygems_version: 3.2.22
209
+ signing_key:
216
210
  specification_version: 4
217
211
  summary: Expose Universa Java API to ruby
218
212
  test_files: []
Binary file