Class: Nanook::PrivateKey
- Inherits:
-
Object
- Object
- Nanook::PrivateKey
- Includes:
- Util
- Defined in:
- lib/nanook/private_key.rb
Overview
The Nanook::PrivateKey
class lets you manage your node's keys.
Constant Summary
Constants included from Util
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
True if keys are equal.
-
#account ⇒ Object
Returns the Account that matches this private key.
-
#create(seed: nil, index: nil) ⇒ Object
Generate a new private public key pair.
-
#hash ⇒ Integer
The hash value is used along with #eql? by the Hash class to determine if two objects reference the same hash key.
- #id ⇒ Object
-
#initialize(rpc, key = nil) ⇒ PrivateKey
constructor
A new instance of PrivateKey.
-
#public_key ⇒ Object
Returns the PublicKey pair for this private key.
- #to_s ⇒ String (also: #inspect)
Constructor Details
#initialize(rpc, key = nil) ⇒ PrivateKey
Returns a new instance of PrivateKey.
10 11 12 13 |
# File 'lib/nanook/private_key.rb', line 10 def initialize(rpc, key = nil) @rpc = rpc @key = key.to_s if key end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Returns true if keys are equal.
21 22 23 24 |
# File 'lib/nanook/private_key.rb', line 21 def ==(other) other.class == self.class && other.id == id end |
#account ⇒ Object
Returns the Account that matches this private key. The account may not exist yet in the ledger.
71 72 73 |
# File 'lib/nanook/private_key.rb', line 71 def account as_account([:account]) end |
#create(seed: nil, index: nil) ⇒ Object
Generate a new private public key pair. Returns the new Nanook::PrivateKey. The public key can be retrieved by calling `#public_key` on the private key.
Examples:
private_key = nanook.private_key.create
private_key.public_key # => Nanook::PublicKey pair for the private key
deterministic_private_key = nanook.private_key.create(seed: seed, index: 0)
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/nanook/private_key.rb', line 48 def create(seed: nil, index: nil) skip_key_required! params = { _access: :private, _coerce: Hash } @key = if seed.nil? rpc(:key_create, params) else raise ArgumentError, 'index argument is required when seed is given' if index.nil? rpc(:deterministic_key, params.merge(seed: seed, index: index)) end self end |
#hash ⇒ Integer
The hash value is used along with #eql? by the Hash class to determine if two objects reference the same hash key.
31 32 33 |
# File 'lib/nanook/private_key.rb', line 31 def hash id.hash end |
#id ⇒ Object
15 16 17 |
# File 'lib/nanook/private_key.rb', line 15 def id @key end |
#public_key ⇒ Object
Returns the Nanook::PublicKey pair for this private key.
78 79 80 |
# File 'lib/nanook/private_key.rb', line 78 def public_key as_public_key([:public]) end |
#to_s ⇒ String Also known as: inspect
83 84 85 |
# File 'lib/nanook/private_key.rb', line 83 def to_s "#{self.class.name}(id: \"#{short_id}\")" end |