universa 3.13.1.1 → 3.14.2.2

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.
Files changed (31) 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.1.jar → com.icodici.common_tools-3.14.2.jar} +0 -0
  7. data/bin/umi/lib/{com.icodici.crypto-3.13.1.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/service.rb +15 -6
  14. data/lib/universa/umi.rb +1 -1
  15. data/lib/universa/version.rb +1 -1
  16. data/samples/load_contract.rb +10 -0
  17. data/samples/safe58_sample.rb +45 -0
  18. data/universa.gemspec +2 -2
  19. metadata +18 -25
  20. data/bin/umi/lib/com.fasterxml.jackson.core.jackson-annotations-2.8.11.jar +0 -0
  21. data/bin/umi/lib/com.fasterxml.jackson.core.jackson-core-2.8.11.jar +0 -0
  22. data/bin/umi/lib/com.fasterxml.jackson.core.jackson-databind-2.8.11.1.jar +0 -0
  23. data/bin/umi/lib/com.fasterxml.jackson.datatype.jackson-datatype-jdk8-2.8.11.jar +0 -0
  24. data/bin/umi/lib/com.fasterxml.jackson.datatype.jackson-datatype-jsr310-2.8.11.jar +0 -0
  25. data/bin/umi/lib/com.icodici.umi-0.8.66.jar +0 -0
  26. data/bin/umi/lib/com.icodici.universa_core-3.13.1.jar +0 -0
  27. data/bin/umi/lib/com.typesafe.play.play-functional_2.12-2.6.10.jar +0 -0
  28. data/bin/umi/lib/com.typesafe.play.play-json_2.12-2.6.10.jar +0 -0
  29. data/bin/umi/lib/joda-time.joda-time-2.9.9.jar +0 -0
  30. data/bin/umi/lib/org.scala-lang.scala-reflect-2.12.7.jar +0 -0
  31. 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: f6c5bd0ff2fe994b5ab3d60bf1a5b94ae57632b442d7ea0846ac6c49a92a1fc1
4
- data.tar.gz: 8f6d65ecbedf21879f329359e3af7fc6095b42718349fd11bd49bb6fa45ac4e9
3
+ metadata.gz: 6487e468be6041ca989e00499911941b71f8684fcdf171e9659c3934f26a54f8
4
+ data.tar.gz: 0e04d054937e42a0955a48597fc20766327b2438d036c490d4dbe12b79d86ae5
5
5
  SHA512:
6
- metadata.gz: fb6602ec3a8df8cd6c88ccaf1690311658e23ebb088d62e6cb4a5e6255027182ac4a5e4ac7c723bdb9cc5a5f072f9d9169c1484799227cc8bfe6b9756e3cbb71
7
- data.tar.gz: 2896498a14742c58a311e31a70b434d62f2f64d171680ef2f522e83ce5812dd570059db74999e2cb441af83226e8a90397fe7438da6aaf1d9d3dffde0bc51f6d
6
+ metadata.gz: 3106d98aa41169ff04865fcf6b21705077f0d365ac9064cb577b8a5e68af6aafc8086999f10d2da3e5641e8f0e59d839fa68011a9ff4acfb18c44c8c7197ad36
7
+ data.tar.gz: f5be6b114d0df7d4e625c6b8c4a4a7a2469105c10f8fe9fcba1d792e8f361a4827040956ddb1ca2bbc9fb771027d19c83d5873daf32ba4d0cf8e22eead6475b4
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.66.jar:$lib_dir/org.scala-lang.scala-library-2.12.7.jar:$lib_dir/com.icodici.universa_core-3.13.1.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.1.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.1.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.66.jar;%APP_LIB_DIR%\org.scala-lang.scala-library-2.12.7.jar;%APP_LIB_DIR%\com.icodici.universa_core-3.13.1.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.1.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.1.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
@@ -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
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.1.1"
3
+ VERSION = "3.14.2.2"
4
4
  end
@@ -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.1.1
4
+ version: 3.14.2.2
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-01 00:00:00.000000000 Z
11
+ date: 2021-09-21 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.1.jar
153
- - bin/umi/lib/com.icodici.crypto-3.13.1.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.66.jar
156
- - bin/umi/lib/com.icodici.universa_core-3.13.1.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
@@ -191,12 +182,14 @@ files:
191
182
  - lib/universa/version.rb
192
183
  - lib/universa/weak_reference.rb
193
184
  - sample_ping.rb
185
+ - samples/load_contract.rb
186
+ - samples/safe58_sample.rb
194
187
  - universa.gemspec
195
- homepage:
188
+ homepage:
196
189
  licenses:
197
190
  - MIT
198
191
  metadata: {}
199
- post_install_message:
192
+ post_install_message:
200
193
  rdoc_options: []
201
194
  require_paths:
202
195
  - lib
@@ -211,8 +204,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
211
204
  - !ruby/object:Gem::Version
212
205
  version: '0'
213
206
  requirements: []
214
- rubygems_version: 3.0.3
215
- signing_key:
207
+ rubygems_version: 3.2.15
208
+ signing_key:
216
209
  specification_version: 4
217
210
  summary: Expose Universa Java API to ruby
218
211
  test_files: []
Binary file