Sha256: fcced0607e15efb773b722b60ea58a200fa5b1571dea6549e481a31ae7f0a7d2
Contents?: true
Size: 657 Bytes
Versions: 24
Compression:
Stored size: 657 Bytes
Contents
module Etherlite::Utils class ValidateAddress < PowerTypes::Command.new(:address) MATCHER = /^0x[0-9a-fA-F]{40}$/ def perform return false unless MATCHER === @address return false if /[A-F]/ === @address && !valid_checksum? true end private def valid_checksum? trimmed_address = @address.gsub(/^0x/, '') address_hash = Etherlite::Utils.sha3 trimmed_address.downcase trimmed_address.chars.each_with_index do |c, i| hash_byte = address_hash[i].to_i(16) return false if (hash_byte > 7 && c.upcase != c) || (hash_byte <= 7 && c.downcase != c) end true end end end
Version data entries
24 entries across 24 versions & 1 rubygems