Class: PolarLoop::Wallet

Inherits:
Object
  • Object
show all
Defined in:
lib/polarloop/wallet.rb

Constant Summary collapse

BIP44_BASE_PATH =
"m/44'/60'/0'/0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mnemonic, index: 0) ⇒ Wallet

Returns a new instance of Wallet.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/polarloop/wallet.rb', line 12

def initialize(mnemonic, index: 0)
  validate_mnemonic!(mnemonic)
  seed_hex = BipMnemonic.to_seed(mnemonic: mnemonic)
  master = MoneyTree::Master.new(seed_hex: seed_hex)
  node = master.node_for_path("#{BIP44_BASE_PATH}/#{index}")
  @key = Eth::Key.new(priv: node.private_key.to_hex)
rescue WalletError
  raise
rescue => e
  raise WalletError, "Failed to derive wallet: #{e.message}"
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



10
11
12
# File 'lib/polarloop/wallet.rb', line 10

def key
  @key
end

Instance Method Details

#addressObject



24
25
26
# File 'lib/polarloop/wallet.rb', line 24

def address
  @key.address.to_s
end