Sha256: c144bb6df13408049e694736dec9e400c80894df38a92e0d0c51cb1d0ff644c6
Contents?: true
Size: 885 Bytes
Versions: 3
Compression:
Stored size: 885 Bytes
Contents
#!/usr/bin/env ruby require 'bech32' require 'thor' class CLI < Thor desc 'encode hrp data bech32/bech32m', 'Encoding data to bech32/bech32m string.' def encode(hrp, data, type) if type && !['bech32', 'bech32m'].include?(type) puts 'Invalid type value. type must be bech32 or bech32m.' else spec = type.nil? || type == 'bech32' ? 1 : 2 data = [data].pack('H*').unpack('C*') puts Bech32.encode(hrp, data, spec) end end desc 'decode "bech32string"', 'Decoding bech32/bech32m string.' def decode(bech32_str) bech32 = Bech32.decode(bech32_str, bech32_str.length) if bech32 puts <<~EOS HRP: #{bech32[0]} DATA: #{bech32[1].pack('C*').unpack1('H*')} TYPE: #{bech32[2] == Bech32::Encoding::BECH32 ? 'bech32' : 'bech32m'} EOS else puts 'Can not decode.' end end end CLI.start(ARGV)
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
bech32-1.4.0 | exe/bech32 |
bech32-1.3.0 | exe/bech32 |
bech32-1.2.1 | exe/bech32 |