# frozen_string_literal: true module Hashtastic class EthereumSHA3 class << self def call(*values) values = values.flatten.map do |value| if value.is_a?(String) if value[0..1] == '0x' value[2..-1] else value.unpack('H*') end elsif value.is_a?(Numeric) value.to_s(16).rjust(64, '0') else '' end end "0x#{Digest::SHA3.hexdigest(packed_values(values), 256)}" end def packed_values(values) [values.join].pack('H*') end alias digest call end end end