class Zilliqa::Crypto::KeyTool
Public Class Methods
generate_private_key()
click to toggle source
# File lib/zilliqa/crypto/key_tool.rb, line 14 def self.generate_private_key Util.encode_hex KeyTool.generate_random_bytes(32) end
generate_random_bytes(size)
click to toggle source
# File lib/zilliqa/crypto/key_tool.rb, line 18 def self.generate_random_bytes(size) SecureRandom.random_bytes(size) end
get_address_from_private_key(private_key)
click to toggle source
getAddressFromPrivateKey
takes a hex-encoded string (private key) and returns its corresponding 20-byte hex-encoded address.
@param {string} privateKey @returns {string}
# File lib/zilliqa/crypto/key_tool.rb, line 44 def self.get_address_from_private_key(private_key) public_key = KeyTool.get_public_key_from_private_key(private_key) KeyTool.get_address_from_public_key(public_key) end
get_address_from_public_key(public_key)
click to toggle source
getAddressFromPublicKey
takes hex-encoded string and returns the corresponding address
@param {string} public_key @returns {string}
# File lib/zilliqa/crypto/key_tool.rb, line 55 def self.get_address_from_public_key(public_key) orig_address = Digest::SHA256.hexdigest Util.decode_hex public_key Util::Bech32.to_bech32(orig_address[24..-1].downcase) end
get_public_key_from_private_key(private_key, is_compressed = true)
click to toggle source
getPubKeyFromPrivateKey
takes a hex-encoded string (private key) and returns its corresponding hex-encoded 33-byte public key.
@param {string} privateKey @returns {string}
# File lib/zilliqa/crypto/key_tool.rb, line 29 def self.get_public_key_from_private_key(private_key, is_compressed = true) is_raw = private_key.length == 32 pk = PrivateKey.new(privkey: private_key, raw: is_raw) (Util.encode_hex pk.pubkey.serialize(compressed: is_compressed)).downcase end
new(private_key)
click to toggle source
# File lib/zilliqa/crypto/key_tool.rb, line 8 def initialize(private_key) is_raw = private_key.length == 32 @pk = PrivateKey.new(privkey: private_key, raw: is_raw) end