Sha256: bfefe1dae0e6f691dea540a744c1d513c5c3dc3e3d53748282de441bc256c5ca

Contents?: true

Size: 1.19 KB

Versions: 7

Compression:

Stored size: 1.19 KB

Contents

module Zilliqa
  module Account
    class Account
      attr_reader :private_key, :public_key, :address
      def initialize(private_key)
        @private_key = private_key
        @public_key = Zilliqa::Crypto::KeyTool.get_public_key_from_private_key(private_key, true)
        @address = Zilliqa::Crypto::KeyTool.get_address_from_public_key(@public_key)
      end

      # Takes a JSON-encoded keystore and passphrase, returning a fully
      # instantiated Account instance.
      def self.from_file(file, passphrase)
        key_store = Zilliqa::Crypto::KeyStore.new
        private_key = key_store.decrypt_private_key(file, passphrase)
        Account.new(private_key)
      end

      # Convert an Account instance to a JSON-encoded keystore.
      def to_file(passphrase, type)
        key_store = Zilliqa::Crypto::KeyStore.new
        json = key_store.encrypt_private_key(@private_key, passphrase, type);
      end

      # sign the passed in transaction with the account's private and public key
      def sign_transaction(tx)
        message = tx.bytes
        message_hex = Util.encode_hex(message)

        Zilliqa::Crypto::Schnorr.sign(message_hex, @private_key, @public_key)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
zilliqa-0.1.7 lib/zilliqa/account/account.rb
zilliqa-0.1.6 lib/zilliqa/account/account.rb
zilliqa-0.1.5 lib/zilliqa/account/account.rb
zilliqa-0.1.4 lib/zilliqa/account/account.rb
zilliqa-0.1.3 lib/zilliqa/account/account.rb
zilliqa-0.1.2 lib/zilliqa/account/account.rb
zilliqa-0.1.1 lib/zilliqa/account/account.rb