lib/universa/contract.rb in universa-3.11.4.2 vs lib/universa/contract.rb in universa-3.11.4.3
- old
+ new
@@ -1,6 +1,7 @@
require 'bigdecimal'
+require 'universa/lazy'
module Universa
# Adapter for com.icodici.crypto
class KeyInfo < RemoteAdapter
@@ -144,28 +145,29 @@
# Get binary representation. It is shorter than string representation but contain non-printable characters and
# can cause problems if treated like a string. Use {#to_s} to get string representation instead.
#
# @return [String] binary string
def bytes
- get_digest
+ @bytes ||= get_digest
end
+
# Get string representation. It is, actually, base64 encoded string representation. Longer, but could easily
# be transferred with text protocols.
#
# @return [String] string representation
def to_s
- Base64.encode64(get_digest).gsub(/\s/, '')
+ @str ||= Base64.encode64(get_digest).gsub(/\s/, '')
end
# Converts to URL-safe varianot of base64, as RFC 3548 suggests:
# the 63:nd / character with the underscore _
# the 62:nd + character with the minus -
#
# Could be decoded safely back with {HashId.from_string} but not (most likely) with JAVA API itself
# @return [String] RFC3548 modified base64
def to_url_safe_string
- Base64.encode64(get_digest).gsub(/\s/, '').gsub('/', '_').gsub('+', '-')
+ @urlsafe_str ||= Base64.encode64(get_digest).gsub(/\s/, '').gsub('/', '_').gsub('+', '-')
end
# To use it as a hash key_address.
# @return hash calculated over the digest bytes
def hash
\ No newline at end of file