module Universa

The Universa gem

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

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

Constants

ALNUMS
NUMBERS
VERSION

Current gem version

Public Instance Methods

camelize_lower() click to toggle source
# File lib/universa/string_utils.rb, line 3
def camelize_lower
  first, *rest = split('_').delete_if(&:empty?)
  [first, *rest.map(&:capitalize)].join
end
derive_key(password, salt, rounds: 50000, prf: "HMAC_SHA256", tag: "default_tag") click to toggle source

Derive symmetric key from a password using PBKDF2 algorithm

# 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
print_stack_trace() click to toggle source

syntax sugar: print exception class, message and stack trace (with line feeds) to the stderr.

random_alnums() click to toggle source
# File lib/universa/tools.rb, line 130
def random_alnums
  to_i.times.map {ALNUMS.sample}.join('')
end
random_bytes() click to toggle source
# File lib/universa/tools.rb, line 138
def random_bytes
  to_i.times.map {rand(256).chr}.join('').force_encoding('binary')
end
random_digits() click to toggle source
# File lib/universa/tools.rb, line 134
def random_digits
  to_i.times.map {NUMBERS.sample}.join('')
end
retry_with_timeout(max_timeout = 25, max_times = 3, &block) click to toggle source
# 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