Class: EIP55::Address

Inherits:
Object
  • Object
show all
Defined in:
lib/eip55/address.rb

Instance Method Summary collapse

Constructor Details

#initialize(address) ⇒ Address

Returns a new instance of Address.



6
7
8
# File 'lib/eip55/address.rb', line 6

def initialize address
  @address = Util.prefix(address)
end

Instance Method Details

#checksummedObject



20
21
22
23
24
25
26
27
28
# File 'lib/eip55/address.rb', line 20

def checksummed
  raise InvalidAddressError.new("Invalid address: #{address}") unless matches_any_format?

  cased = unprefixed.chars.zip(checksum.chars).map do |char, check|
    check.match?(/[0-7]/) ? char.downcase : char.upcase
  end

  Util.prefix(cased.join)
end

#valid?Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
16
17
18
# File 'lib/eip55/address.rb', line 10

def valid?
  if !matches_any_format?
    false
  elsif not_checksummed?
    true
  else
    checksum_matches?
  end
end