Method: Base58::Base.decode

Defined in:
lib/base58-alphabets/base.rb

.decode(str_or_bytes) ⇒ Object

Converts a base58 string to a base10 integer.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/base58-alphabets/base.rb', line 25

def self.decode( str_or_bytes )
  if str_or_bytes.is_a?( Array )
    bytes = str_or_bytes
  else  ## assume string

    str   = str_or_bytes
    bytes = str.each_char.reduce([]) do |bytes,char|
                                       byte = number[char]
                                       raise ArgumentError, "Value passed not a valid base58 string - >#{char}< not found in alphabet"  if byte.nil?
                                       bytes << byte
                                       bytes
                                     end
  end
  Base58._pack( bytes )
end