Module: CoinOp::Encodings
- Extended by:
- Encodings
- Included in:
- Bit::Input, Bit::MultiNode, Bit::MultiWallet, Bit::Output, Bit::Script, Bit::SparseInput, Bit::Transaction, Crypto::PassphraseBox, Crypto::PassphraseBox, Encodings
- Defined in:
- lib/coin-op/encodings.rb
Instance Method Summary collapse
- #base58(blob) ⇒ Object
- #decode_base58(string) ⇒ Object
- #decode_hex(string) ⇒ Object
- #hex(blob) ⇒ Object
- #int_to_byte_array(i, endianness: :little) ⇒ Object
Instance Method Details
#base58(blob) ⇒ Object
17 18 19 |
# File 'lib/coin-op/encodings.rb', line 17 def base58(blob) ::Bitcoin.encode_base58(self.hex(blob)) end |
#decode_base58(string) ⇒ Object
21 22 23 |
# File 'lib/coin-op/encodings.rb', line 21 def decode_base58(string) self.decode_hex(::Bitcoin.decode_base58(string)) end |
#decode_hex(string) ⇒ Object
13 14 15 |
# File 'lib/coin-op/encodings.rb', line 13 def decode_hex(string) [string].pack("H*") end |
#hex(blob) ⇒ Object
9 10 11 |
# File 'lib/coin-op/encodings.rb', line 9 def hex(blob) blob.unpack("H*")[0] end |
#int_to_byte_array(i, endianness: :little) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/coin-op/encodings.rb', line 25 def int_to_byte_array(i, endianness: :little) arr = i.to_s(16).scan(/../).map { |x| x.hex.chr } if endianness == :little arr.reverse.join else arr.join end end |