Module: Universa

Included in:
Client
Defined in:
lib/universa.rb,
lib/universa/umi.rb,
lib/universa/dump.rb,
lib/universa/keys.rb,
lib/universa/lazy.rb,
lib/universa/tools.rb,
lib/universa/binder.rb,
lib/universa/client.rb,
lib/universa/errors.rb,
lib/universa/service.rb,
lib/universa/version.rb,
lib/universa/contract.rb,
lib/universa/chain_store.rb,
lib/universa/string_utils.rb,
lib/universa/weak_reference.rb,
lib/universa/stored_contract.rb,
lib/universa/universa_helpers.rb

Overview

The Universa gem

Currently, only direct access to the Java API is available:

  • class UMI. Use it to get direct access to the Java API

Ruby-wrappers and tools are not yet available. Still direct access could be all you need at the time.

Defined Under Namespace

Modules: Checks, FSStore, Lazy, Parallel Classes: Binder, ChainStore, ChangeOwnerPermission, ChangeRolePermission, Client, Compound, Connection, Contract, ContractService, ContractState, Duration, Error, EscrowHelper, ExtendedSignature, HashId, IllegalStateError, InterchangeError, KeyAddress, KeyInfo, LazyValue, ListRole, ModifyDataPermission, NetworkError, NotFoundError, PBKDF2, Parcel, PrivateKey, PublicKey, QuorumVoteRole, Ref, Reference, ReferenceCreationData, RemoteAdapter, RevokePermission, Role, RoleLink, Safe58, SecureLoanHelper, Service, SimpleRole, SmartHash, SplitJoinPermission, StoreError, StoredContractBase, SymmetricKey, TransactionPack, UMI, UmiClient, UnsContract, WeakReference

Constant Summary collapse

ALNUMS =
(alnums + alnums.downcase + '_' + '0123456789').chars.to_ary
NUMBERS =
"0123456789".chars.to_ary
VERSION =

Current gem version

"3.14.5"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.dump_bytes(data, line_bytes = 16) ⇒ String

Convert binary data to a human-readable dump string, like

000000 27 23 64 61 74 61 c4 2d 0f |'#data.-.| 000008 0f 1f 43 63 6f 6e 74 72 61 |..Ccontra|

Parameters:

  • data (String)

    data to dump

  • line_bytes (Number) (defaults to: 16)

    how many bytes to show in each line

Returns:

  • (String)

    dump as a string



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/universa/dump.rb', line 13

def dump_bytes data, line_bytes=16
  data.force_encoding Encoding::BINARY
  offset = 0
  res = []

  while( offset < data.length )

    left = "%06x" % offset
    portion = data[offset..(offset+line_bytes)].bytes

    bytes = portion.map { |x| "%02x" % x }.join(' ')
    chars = portion.map { |c| x = c.ord; x >= 32 && x <= 'z'.ord ? x.chr : '.' }.join('')

    if chars.length < line_bytes
      pad = line_bytes - chars.length + 1
      chars += ' ' * pad
      bytes += '   ' * pad
    end

    res << "#{left} #{bytes} |#{chars}|"

    offset += line_bytes
  end
  res.join("\n")
end

Instance Method Details

#derive_key(password, salt, rounds: 50000, prf: "HMAC_SHA256", tag: "default_tag") ⇒ Object

Derive symmetric key from a password using PBKDF2 algorithm



12
13
14
15
16
17
# File 'lib/universa/contract.rb', line 12

def derive_key(password, salt, rounds: 50000, prf: "HMAC_SHA256", tag: "default_tag")
  salt.is_a?(String) and salt = salt.force_encoding('binary')
  tag && tag.is_a?(String) and tag = tag.force_encoding('binary')
  ki = KeyInfo.new(prf, rounds, salt, tag)
  ki.derivePassword(password)
end

#retry_with_timeout(max_timeout = 25, max_times = 3, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/universa/tools.rb', line 10

def retry_with_timeout(max_timeout = 25, max_times = 3, &block)
  attempt = 0
  begin
    Timeout::timeout(max_timeout, &block)
  rescue
    attempt += 1
    puts "timeout: retry (#$!): #{attempt}"
    retry if attempt < max_times
    raise
  end
end