class Banano::Key
Public Class Methods
new(node:, key: nil)
click to toggle source
# File lib/banano/key.rb, line 5 def initialize(node:, key: nil) @node = node @key = key end
Public Instance Methods
expand()
click to toggle source
Derive public key and account from private key
# File lib/banano/key.rb, line 21 def expand return {} if @key.nil? rpc(action: :key_expand, params: {key: @key}) end
generate(seed: nil, index: nil)
click to toggle source
# File lib/banano/key.rb, line 10 def generate(seed: nil, index: nil) if seed.nil? && index.nil? rpc(action: :key_create) elsif !seed.nil? && !index.nil? rpc(action: :deterministic_key, params: {seed: seed, index: index}) else raise ArgumentError, "Method must be called with either seed AND index params" end end
id()
click to toggle source
# File lib/banano/key.rb, line 27 def id @key end
info()
click to toggle source
# File lib/banano/key.rb, line 31 def info key_required! rpc(action: :key_expand) end
Private Instance Methods
key_required!()
click to toggle source
# File lib/banano/key.rb, line 43 def key_required! raise ArgumentError, "Key must be present" if @key.nil? end
rpc(action:, params: {})
click to toggle source
# File lib/banano/key.rb, line 38 def rpc(action:, params: {}) p = @key.nil? ? {} : {key: @key} @node.rpc(action: action, params: p.merge(params)) end