Class: Crypto::Keys::PublicKey
- Inherits:
-
Object
- Object
- Crypto::Keys::PublicKey
- Defined in:
- lib/crypto/keys/public_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(public_key_hex, network = MAINNET) ⇒ PublicKey
constructor
A new instance of PublicKey.
- #is_valid? ⇒ Boolean
Constructor Details
#initialize(public_key_hex, network = MAINNET) ⇒ PublicKey
Returns a new instance of PublicKey.
5 6 7 8 9 |
# File 'lib/crypto/keys/public_key.rb', line 5 def initialize(public_key_hex, network = MAINNET) @public_key_hex = public_key_hex @network = network raise AxentroError, "invalid public key: #{@public_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/public_key.rb', line 3 def network @network end |
Class Method Details
Instance Method Details
#address ⇒ Object
27 28 29 |
# File 'lib/crypto/keys/public_key.rb', line 27 def address Address.new(KeyUtils.get_address_from_public_key(self), @network) end |
#as_bytes ⇒ Object
23 24 25 |
# File 'lib/crypto/keys/public_key.rb', line 23 def as_bytes KeyUtils.to_bytes(@public_key_hex) end |
#as_hex ⇒ Object
19 20 21 |
# File 'lib/crypto/keys/public_key.rb', line 19 def as_hex @public_key_hex end |
#is_valid? ⇒ Boolean
31 32 33 |
# File 'lib/crypto/keys/public_key.rb', line 31 def is_valid? !@public_key_hex.nil? && @public_key_hex.size == 64 end |