class Neb::Account
Attributes
address_obj[R]
password[RW]
private_key_obj[R]
public_key_obj[R]
set_password[RW]
Public Class Methods
create(password: nil)
click to toggle source
# File lib/neb/account.rb, line 19 def create(password: nil) new(private_key: PrivateKey.random.to_s, password: password) end
from_key(key:, password:)
click to toggle source
# File lib/neb/account.rb, line 23 def from_key(key:, password:) new(private_key: Key.decrypt(key, password), password: password) end
from_key_file(key_file:, password:)
click to toggle source
# File lib/neb/account.rb, line 27 def from_key_file(key_file:, password:) from_key(key: File.read(key_file), password: password) end
new(private_key:, password: nil)
click to toggle source
# File lib/neb/account.rb, line 11 def initialize(private_key:, password: nil) @private_key_obj = PrivateKey.new(private_key) @public_key_obj = @private_key_obj.to_pubkey_obj @address_obj = @public_key_obj.to_address_obj @password = password end
Public Instance Methods
address()
click to toggle source
# File lib/neb/account.rb, line 40 def address @address_obj.to_s end
private_key()
click to toggle source
# File lib/neb/account.rb, line 32 def private_key @private_key_obj.to_s end
public_key()
click to toggle source
# File lib/neb/account.rb, line 36 def public_key @public_key_obj.to_s end
to_key()
click to toggle source
# File lib/neb/account.rb, line 44 def to_key raise ArgumentError.new("must set_password first") if password.blank? Key.encrypt(address, private_key, password) end
to_key_file(file_path: nil)
click to toggle source
# File lib/neb/account.rb, line 49 def to_key_file(file_path: nil) file_path = Neb.root.join('tmp', "#{address}.json") if file_path.blank? File.open(file_path, 'w+') { |f| f << Utils.to_json(to_key) } file_path.to_s end