class Crypto::Keys::PrivateKey

Attributes

network[R]

Public Class Methods

from_bytes(bytes, network = MAINNET) click to toggle source
# File lib/crypto/keys/private_key.rb, line 15
def self.from_bytes(bytes, network = MAINNET)
    PrivateKey.new(KeyUtils.to_hex(bytes), network)
end
from_hex(hex, network = MAINNET) click to toggle source
# File lib/crypto/keys/private_key.rb, line 11
def self.from_hex(hex, network = MAINNET)
    PrivateKey.new(hex, network)
end
new(private_key_hex, network = MAINNET) click to toggle source
# File lib/crypto/keys/private_key.rb, line 5
def initialize(private_key_hex, network = MAINNET)
    @private_key_hex = private_key_hex
    @network = network
    raise AxentroError, "invalid private key: '#{@private_key_hex}'" unless is_valid?
end

Public Instance Methods

address() click to toggle source
# File lib/crypto/keys/private_key.rb, line 37
def address 
    Address.new(KeyUtils.get_address_from_public_key(self.public_key), @network)
end
as_bytes() click to toggle source
# File lib/crypto/keys/private_key.rb, line 23
def as_bytes
    KeyUtils.to_bytes(@private_key_hex)
end
as_hex() click to toggle source
# File lib/crypto/keys/private_key.rb, line 19
def as_hex
    @private_key_hex
end
is_valid?() click to toggle source
# File lib/crypto/keys/private_key.rb, line 41
def is_valid?
    !@private_key_hex.nil? && @private_key_hex.size == 64
end
public_key() click to toggle source
# File lib/crypto/keys/private_key.rb, line 31
def public_key
    signing_key = Ed25519::SigningKey.new([@private_key_hex].pack("H*"))
    hex_public_key = signing_key.keypair.unpack("H*").first[64..-1]
    PublicKey.new(hex_public_key, @network)
end
wif() click to toggle source
# File lib/crypto/keys/private_key.rb, line 27
def wif 
    Wif.from(self, @network)
end