module Ethereum::Tx::Utils
Public Instance Methods
base256_to_int(string)
click to toggle source
# File lib/ethereum-tx/utils.rb, line 31 def base256_to_int(string) string.bytes.inject do |result, byte| result *= 256 result + byte end end
bin_to_hex(string)
click to toggle source
# File lib/ethereum-tx/utils.rb, line 23 def bin_to_hex(string) string.unpack("H*")[0] end
hex_to_bin(string)
click to toggle source
# File lib/ethereum-tx/utils.rb, line 27 def hex_to_bin(string) [string].pack("H*") end
int_to_base256(int)
click to toggle source
# File lib/ethereum-tx/utils.rb, line 38 def int_to_base256(int) bytes = [] while int > 0 do bytes.unshift(int % 256) int /= 256 end bytes.pack('C*') end
keccak256(message)
click to toggle source
# File lib/ethereum-tx/utils.rb, line 7 def keccak256(message) Digest::SHA3.new(256).digest(message) end
normalize_address(address)
click to toggle source
# File lib/ethereum-tx/utils.rb, line 11 def normalize_address(address) if address.nil? || address == '' '' elsif address.size == 40 hex_to_bin address elsif address.size == 42 && address[0..1] == '0x' hex_to_bin address[2..-1] else address end end
v_r_s_for(signature)
click to toggle source
# File lib/ethereum-tx/utils.rb, line 47 def v_r_s_for(signature) [ signature[0].bytes[0], Utils.base256_to_int(signature[1..32]), Utils.base256_to_int(signature[33..65]), ] end