Class: Crypto::Keys::PrivateKey
- Inherits:
-
Object
- Object
- Crypto::Keys::PrivateKey
- Defined in:
- lib/crypto/keys/private_key.rb
Instance Attribute Summary collapse
-
#network ⇒ Object
readonly
Returns the value of attribute network.
Class Method Summary collapse
Instance Method Summary collapse
- #address ⇒ Object
- #as_bytes ⇒ Object
- #as_hex ⇒ Object
-
#initialize(private_key_hex, network = MAINNET) ⇒ PrivateKey
constructor
A new instance of PrivateKey.
- #is_valid? ⇒ Boolean
- #public_key ⇒ Object
- #wif ⇒ Object
Constructor Details
#initialize(private_key_hex, network = MAINNET) ⇒ PrivateKey
Returns a new instance of PrivateKey.
5 6 7 8 9 |
# 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 |
Instance Attribute Details
#network ⇒ Object (readonly)
Returns the value of attribute network.
3 4 5 |
# File 'lib/crypto/keys/private_key.rb', line 3 def network @network end |
Class Method Details
.from_bytes(bytes, network = MAINNET) ⇒ Object
15 16 17 |
# 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) ⇒ Object
11 12 13 |
# File 'lib/crypto/keys/private_key.rb', line 11 def self.from_hex(hex, network = MAINNET) PrivateKey.new(hex, network) end |
Instance Method Details
#address ⇒ Object
37 38 39 |
# 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 ⇒ Object
23 24 25 |
# File 'lib/crypto/keys/private_key.rb', line 23 def as_bytes KeyUtils.to_bytes(@private_key_hex) end |
#as_hex ⇒ Object
19 20 21 |
# File 'lib/crypto/keys/private_key.rb', line 19 def as_hex @private_key_hex end |
#is_valid? ⇒ Boolean
41 42 43 |
# File 'lib/crypto/keys/private_key.rb', line 41 def is_valid? !@private_key_hex.nil? && @private_key_hex.size == 64 end |