Method: Bitcoin::Base58.decode
- Defined in:
- lib/bitcoin/base58.rb
.decode(base58_val) ⇒ Object
decode base58 string to hex value.
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/bitcoin/base58.rb', line 24 def decode(base58_val) int_val = 0 base58_val.reverse.split(//).each_with_index do |char,index| raise ArgumentError, 'Value passed not a valid Base58 String.' if (char_index = ALPHABET.index(char)).nil? int_val += char_index * (SIZE ** index) end s = int_val.to_even_length_hex s = '' if s == '00' leading_zero_bytes = (base58_val.match(/^([1]+)/) ? $1 : '').size s = ('00' * leading_zero_bytes) + s if leading_zero_bytes > 0 s end |