universa 3.14.2.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.
- checksums.yaml +4 -4
- data/lib/universa/contract.rb +11 -2
- data/lib/universa/dump.rb +40 -0
- data/lib/universa/version.rb +1 -1
- data/samples/load_contract.rb +10 -0
- data/samples/safe58_sample.rb +45 -0
- data/universa.gemspec +2 -2
- metadata +14 -11
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 6487e468be6041ca989e00499911941b71f8684fcdf171e9659c3934f26a54f8
         | 
| 4 | 
            +
              data.tar.gz: 0e04d054937e42a0955a48597fc20766327b2438d036c490d4dbe12b79d86ae5
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 3106d98aa41169ff04865fcf6b21705077f0d365ac9064cb577b8a5e68af6aafc8086999f10d2da3e5641e8f0e59d839fa68011a9ff4acfb18c44c8c7197ad36
         | 
| 7 | 
            +
              data.tar.gz: f5be6b114d0df7d4e625c6b8c4a4a7a2469105c10f8fe9fcba1d792e8f361a4827040956ddb1ca2bbc9fb771027d19c83d5873daf32ba4d0cf8e22eead6475b4
         | 
    
        data/lib/universa/contract.rb
    CHANGED
    
    | @@ -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 |  | 
| @@ -253,7 +262,7 @@ module Universa | |
| 253 262 | 
             
                # @return [Contract] simple contact, not sealed
         | 
| 254 263 | 
             
                def self.create issuer_key, expires_at: (Time.now + 90 * 24 * 60 * 60), use_short_address: false
         | 
| 255 264 | 
             
                  contract = Contract.new
         | 
| 256 | 
            -
                  contract.set_expires_at expires_at
         | 
| 265 | 
            +
                  contract.set_expires_at expires_at.utc
         | 
| 257 266 | 
             
                  contract.set_issuer_keys(use_short_address ? issuer_key.short_address : issuer_key.long_address)
         | 
| 258 267 | 
             
                  contract.register_role(contract.issuer.link_as("owner"))
         | 
| 259 268 | 
             
                  contract.register_role(contract.issuer.link_as("creator"))
         | 
| @@ -333,7 +342,7 @@ module Universa | |
| 333 342 | 
             
                # set +expires_at+ field
         | 
| 334 343 | 
             
                # @param [Time] time when this contract will be expired, if yet +APPROVED+.
         | 
| 335 344 | 
             
                def expires_at=(time)
         | 
| 336 | 
            -
                  set_expires_at time
         | 
| 345 | 
            +
                  set_expires_at time.utc
         | 
| 337 346 | 
             
                end
         | 
| 338 347 |  | 
| 339 348 | 
             
                # @return definition data
         | 
| @@ -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
         | 
    
        data/lib/universa/version.rb
    CHANGED
    
    
| @@ -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", "~>  | 
| 40 | 
            -
              spec.add_development_dependency "rake", "~>  | 
| 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.14.2. | 
| 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:  | 
| 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: ' | 
| 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: ' | 
| 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:  | 
| 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:  | 
| 110 | 
            +
                    version: 12.3.3
         | 
| 111 111 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 112 112 | 
             
              name: rspec
         | 
| 113 113 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -164,6 +164,7 @@ files: | |
| 164 164 | 
             
            - lib/universa/chain_store.rb
         | 
| 165 165 | 
             
            - lib/universa/client.rb
         | 
| 166 166 | 
             
            - lib/universa/contract.rb
         | 
| 167 | 
            +
            - lib/universa/dump.rb
         | 
| 167 168 | 
             
            - lib/universa/errors.rb
         | 
| 168 169 | 
             
            - lib/universa/fs_store/entry.rb
         | 
| 169 170 | 
             
            - lib/universa/fs_store/file_store.rb
         | 
| @@ -181,12 +182,14 @@ files: | |
| 181 182 | 
             
            - lib/universa/version.rb
         | 
| 182 183 | 
             
            - lib/universa/weak_reference.rb
         | 
| 183 184 | 
             
            - sample_ping.rb
         | 
| 185 | 
            +
            - samples/load_contract.rb
         | 
| 186 | 
            +
            - samples/safe58_sample.rb
         | 
| 184 187 | 
             
            - universa.gemspec
         | 
| 185 | 
            -
            homepage: | 
| 188 | 
            +
            homepage:
         | 
| 186 189 | 
             
            licenses:
         | 
| 187 190 | 
             
            - MIT
         | 
| 188 191 | 
             
            metadata: {}
         | 
| 189 | 
            -
            post_install_message: | 
| 192 | 
            +
            post_install_message:
         | 
| 190 193 | 
             
            rdoc_options: []
         | 
| 191 194 | 
             
            require_paths:
         | 
| 192 195 | 
             
            - lib
         | 
| @@ -201,8 +204,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 201 204 | 
             
                - !ruby/object:Gem::Version
         | 
| 202 205 | 
             
                  version: '0'
         | 
| 203 206 | 
             
            requirements: []
         | 
| 204 | 
            -
            rubygems_version: 3. | 
| 205 | 
            -
            signing_key: | 
| 207 | 
            +
            rubygems_version: 3.2.15
         | 
| 208 | 
            +
            signing_key:
         | 
| 206 209 | 
             
            specification_version: 4
         | 
| 207 210 | 
             
            summary: Expose Universa Java API to ruby
         | 
| 208 211 | 
             
            test_files: []
         |