Module: Encryption

Extended by:
ActiveSupport::Concern
Included in:
Peatio::Tron::Blockchain, Peatio::Tron::Wallet
Defined in:
lib/peatio/tron/concerns/encryption.rb

Constant Summary collapse

ALGO =
'123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'

Instance Method Summary collapse

Instance Method Details

#abi_encode(*args) ⇒ Object



28
29
30
31
32
# File 'lib/peatio/tron/concerns/encryption.rb', line 28

def abi_encode(*args)
  args.each_with_object('') do |arg, data|
    data.concat(arg.gsub(/\A0x/, '').rjust(64, '0'))
  end
end

#decode_hex(str) ⇒ Object



24
25
26
# File 'lib/peatio/tron/concerns/encryption.rb', line 24

def decode_hex(str)
  [str].pack('H*')
end

#encode_hex(str) ⇒ Object



20
21
22
# File 'lib/peatio/tron/concerns/encryption.rb', line 20

def encode_hex(str)
  str.unpack('H*')[0]
end

#reformat_decode_address(address) ⇒ Object



7
8
9
# File 'lib/peatio/tron/concerns/encryption.rb', line 7

def reformat_decode_address(address)
  base58_to_binary(address)
end

#reformat_encode_address(hexstring) ⇒ Object



11
12
13
14
# File 'lib/peatio/tron/concerns/encryption.rb', line 11

def reformat_encode_address(hexstring)
  sha256 = sha256_encode(sha256_encode(hexstring))
  (hexstring + sha256[0, 8]).hex.digits(58).reverse.map {|i| ALGO[i]}.join
end

#reformat_txid(txid) ⇒ Object



16
17
18
# File 'lib/peatio/tron/concerns/encryption.rb', line 16

def reformat_txid(txid)
  txid
end