module Encryption
Constants
- ALGO
Public Instance Methods
abi_encode(*args)
click to toggle source
# 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)
click to toggle source
# File lib/peatio/tron/concerns/encryption.rb, line 24 def decode_hex(str) [str].pack('H*') end
encode_hex(str)
click to toggle source
# File lib/peatio/tron/concerns/encryption.rb, line 20 def encode_hex(str) str.unpack('H*')[0] end
reformat_decode_address(address)
click to toggle source
# File lib/peatio/tron/concerns/encryption.rb, line 7 def reformat_decode_address(address) base58_to_binary(address) end
reformat_encode_address(hexstring)
click to toggle source
# 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)
click to toggle source
# File lib/peatio/tron/concerns/encryption.rb, line 16 def reformat_txid(txid) txid end
Private Instance Methods
base58_to_binary(base58_val)
click to toggle source
# File lib/peatio/tron/concerns/encryption.rb, line 49 def base58_to_binary(base58_val) int_encode_hex(base58_to_int(base58_val))[0, 42] end
base58_to_int(base58_val)
click to toggle source
# File lib/peatio/tron/concerns/encryption.rb, line 40 def base58_to_int(base58_val) int_val = 0 base58_val.reverse.split(//).each_with_index do |char, index| char_index = ALGO.index(char) int_val += (char_index) * (ALGO.length ** (index)) end int_val end
int_encode_hex(int)
click to toggle source
# File lib/peatio/tron/concerns/encryption.rb, line 53 def int_encode_hex int hex = int.to_s(16) (hex.length % 2 == 0) ? hex : ('0' + hex) end
sha256_encode(hexstring)
click to toggle source
# File lib/peatio/tron/concerns/encryption.rb, line 36 def sha256_encode(hexstring) Digest::SHA256.hexdigest([hexstring].pack('H*')) end