Class: Laksa::Account::Account

Inherits:
Object
  • Object
show all
Defined in:
lib/laksa/account/account.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(private_key) ⇒ Account

Returns a new instance of Account.



5
6
7
8
9
# File 'lib/laksa/account/account.rb', line 5

def initialize(private_key)
  @private_key = private_key
  @public_key = Laksa::Crypto::KeyTool.get_public_key_from_private_key(private_key, true)
  @address = Laksa::Crypto::KeyTool.get_address_from_public_key(@public_key)
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



4
5
6
# File 'lib/laksa/account/account.rb', line 4

def address
  @address
end

#private_keyObject (readonly)

Returns the value of attribute private_key.



4
5
6
# File 'lib/laksa/account/account.rb', line 4

def private_key
  @private_key
end

#public_keyObject (readonly)

Returns the value of attribute public_key.



4
5
6
# File 'lib/laksa/account/account.rb', line 4

def public_key
  @public_key
end

Class Method Details

.from_file(file, passphrase) ⇒ Object

Takes a JSON-encoded keystore and passphrase, returning a fully instantiated Account instance.



13
14
15
16
17
# File 'lib/laksa/account/account.rb', line 13

def self.from_file(file, passphrase)
  key_store = Laksa::Crypto::KeyStore.new
  private_key = key_store.decrypt_private_key(file, passphrase)
  Account.new(private_key)
end

Instance Method Details

#sign_transaction(tx) ⇒ Object

sign the passed in transaction with the account’s private and public key



26
27
28
29
30
31
# File 'lib/laksa/account/account.rb', line 26

def sign_transaction(tx)
  message = tx.bytes
  message_hex = Util.encode_hex(message)
  
  Laksa::Crypto::Schnorr.sign(message_hex, @private_key, @public_key)
end

#to_file(passphrase, type) ⇒ Object

Convert an Account instance to a JSON-encoded keystore.



20
21
22
23
# File 'lib/laksa/account/account.rb', line 20

def to_file(passphrase, type)
  key_store = Laksa::Crypto::KeyStore.new
  json = key_store.encrypt_private_key(@private_key, passphrase, type);
end