module Cryptocurrency::Utils
Public Class Methods
bech32_decode(data)
click to toggle source
# File lib/cryptocurrency/utils.rb, line 31 def bech32_decode(data) Bech32.decode(data) end
bech32_encode(hrp, data)
click to toggle source
# File lib/cryptocurrency/utils.rb, line 27 def bech32_encode(hrp, data) Bech32.encode(hrp, data) end
bytes_to_integer(bytes)
click to toggle source
# File lib/cryptocurrency/utils.rb, line 35 def bytes_to_integer(bytes) bytes.unpack1('H*').to_i(16) end
double_sha256(data)
click to toggle source
# File lib/cryptocurrency/utils.rb, line 14 def double_sha256(data) sha256(sha256(data)) end
hash160(data)
click to toggle source
# File lib/cryptocurrency/utils.rb, line 18 def hash160(data) ripemd160(sha256(data)) end
hmac_sha512(key, data)
click to toggle source
# File lib/cryptocurrency/utils.rb, line 22 def hmac_sha512(key, data) digest = OpenSSL::Digest.new('sha512') OpenSSL::HMAC.digest(digest, key, data) end
integer_to_bytes(integer)
click to toggle source
# File lib/cryptocurrency/utils.rb, line 39 def integer_to_bytes(integer) hex = integer.to_s(16) hex = "0#{hex}" if hex.length.odd? [hex].pack('H*') end
ripemd160(data)
click to toggle source
# File lib/cryptocurrency/utils.rb, line 6 def ripemd160(data) Digest::RMD160.digest(data) end
sha256(data)
click to toggle source
# File lib/cryptocurrency/utils.rb, line 10 def sha256(data) Digest::SHA2.new(256).digest(data) end