lib/platon/bech32.rb
def decode(bech, max_length = 90)
    # check uppercase/lowercase
    return nil if bech.bytes.index{|x| x < 33 || x > 126}
    return nil if (bech.downcase != bech && bech.upcase != bech)
    bech = bech.downcase
    # check data length
    pos = bech.rindex(SEPARATOR)
    return nil if pos.nil? || pos + 7 > bech.length || bech.length > max_length
    # check valid charset
    bech[pos+1..-1].each_char{|c|return nil unless CHARSET.include?(c)}
    # split hrp and data
    hrp = bech[0..pos-1]
    data = bech[pos+1..-1].each_char.map{|c|CHARSET.index(c)}
    # check checksum
    spec = verify_checksum(hrp, data)
    spec ? [hrp, data[0..-7], spec] : nil
  end
# Returns the Bech32 decoded hrp and data.
Returns the Bech32 decoded hrp and data.
Returns the Bech32 decoded hrp and data .
def decode(bech, max_length = 90)
    return nil if bech.bytes.index{|x| x < 33 || x > 126}
    return nil if (bech.downcase != bech && bech.upcase != bech)
    bech = bech.downcase
    pos = bech.rindex(SEPARATOR)
    return nil if pos.nil? || pos + 7 > bech.length || bech.length > max_length
    bech[pos+1..-1].each_char{|c|return nil unless CHARSET.include?(c)}
    hrp = bech[0..pos-1]
    data = bech[pos+1..-1].each_char.map{|c|CHARSET.index(c)}
    spec = verify_checksum(hrp, data)
    spec ? [hrp, data[0..-7], spec] : nil
  end
def decode ( bech , max_length = 90 ) return nil if bech . bytes . index { | x | x < 33 || x > 126 } return nil if ( bech . downcase != bech && bech . upcase != bech ) bech = bech . downcase pos = bech . rindex ( SEPARATOR ) return nil if pos . nil? || pos + 7 > bech . length || bech . length > max_length bech [ pos + 1 .. - 1 ] . each_char { | c | return nil unless CHARSET . include? ( c ) } hrp = bech [ 0 .. pos - 1 ] data = bech [ pos + 1 .. - 1 ] . each_char . map { | c | CHARSET . index ( c ) } spec = verify_checksum ( hrp , data ) spec ? [ hrp , data [ 0 .. - 7 ] , spec ] : nil end
Returns the Bech32 decoded hrp and data.
Returns the Bech32 decoded hrp and data .
# check uppercase/lowercase # check data length # check valid charset # split hrp and data # check checksum
bech
max_length