Class: Nanook::Key

Inherits:
Object
  • Object
show all
Defined in:
lib/nanook/key.rb

Overview

The Nanook::Key class lets you manage your node's keys.

Instance Method Summary collapse

Constructor Details

#initialize(rpc, key = nil) ⇒ Key

Returns a new instance of Key.



6
7
8
9
# File 'lib/nanook/key.rb', line 6

def initialize(rpc, key = nil)
  @rpc = rpc
  @key = key
end

Instance Method Details

#generate(seed: nil, index: nil) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/nanook/key.rb', line 11

def generate(seed: nil, index: nil)
  if seed.nil? && index.nil?
    rpc(:key_create)
  elsif !seed.nil? && !index.nil?
    rpc(:deterministic_key, seed: seed, index: index)
  else
    raise ArgumentError, 'This method must be called with either seed AND index params given or no params'
  end
end

#idObject



21
22
23
# File 'lib/nanook/key.rb', line 21

def id
  @key
end

#infoObject



25
26
27
28
# File 'lib/nanook/key.rb', line 25

def info
  key_required!
  rpc(:key_expand)
end

#inspectObject



30
31
32
# File 'lib/nanook/key.rb', line 30

def inspect
  "#{self.class.name}(id: \"#{id}\", object_id: \"#{format('0x00%x', (object_id << 1))}\")"
end