Module: Stellar::Convert
Overview
Generic format conversion module
Instance Method Summary collapse
- #from_base64(base64_string) ⇒ Object
- #from_hex(hex_string) ⇒ Object
-
#pk_to_address(pk) ⇒ Object
Converts a Stellar::PublicKey instance (or any typedef of it such as Stellar::AccountID) to an address.
- #to_base64(string) ⇒ Object
- #to_hex(string) ⇒ Object
Instance Method Details
#from_base64(base64_string) ⇒ Object
20 21 22 |
# File 'lib/stellar/convert.rb', line 20 def from_base64(base64_string) Base64.strict_decode64(base64_string) end |
#from_hex(hex_string) ⇒ Object
12 13 14 |
# File 'lib/stellar/convert.rb', line 12 def from_hex(hex_string) [hex_string].pack("H*") end |
#pk_to_address(pk) ⇒ Object
Converts a Stellar::PublicKey instance (or any typedef of it such as Stellar::AccountID) to an address
26 27 28 |
# File 'lib/stellar/convert.rb', line 26 def pk_to_address(pk) Stellar::Util::StrKey.check_encode(:account_id, pk.ed25519!) end |
#to_base64(string) ⇒ Object
16 17 18 |
# File 'lib/stellar/convert.rb', line 16 def to_base64(string) Base64.strict_encode64(string) end |
#to_hex(string) ⇒ Object
8 9 10 |
# File 'lib/stellar/convert.rb', line 8 def to_hex(string) string.unpack1("H*") end |