Class: BTC::Mnemonic
- Inherits:
-
Object
- Object
- BTC::Mnemonic
- Defined in:
- lib/btcruby/mnemonic.rb
Instance Method Summary collapse
-
#initialize(words: nil, password: "") ⇒ Mnemonic
constructor
A new instance of Mnemonic.
- #keychain ⇒ Object
-
#print_addresses(range: 0..100, network: BTC::Network.mainnet, account: 0) ⇒ Object
For manual testing.
- #seed ⇒ Object
Constructor Details
#initialize(words: nil, password: "") ⇒ Mnemonic
Returns a new instance of Mnemonic.
8 9 10 11 12 13 14 15 |
# File 'lib/btcruby/mnemonic.rb', line 8 def initialize(words: nil, password: "") if words.is_a?(String) words = words.split(" ") end # TODO: check if number of words is correct (12, 15, 18, 21, 24) @words = words @password = password end |
Instance Method Details
#keychain ⇒ Object
21 22 23 |
# File 'lib/btcruby/mnemonic.rb', line 21 def keychain @keychain ||= Keychain.new(seed: seed) end |
#print_addresses(range: 0..100, network: BTC::Network.mainnet, account: 0) ⇒ Object
For manual testing
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/btcruby/mnemonic.rb', line 49 def print_addresses(range: 0..100, network: BTC::Network.mainnet, account: 0) kc = keychain.bip44_keychain(network: network).bip44_account_keychain(account) puts "Addresses for account #{account} on #{network.name}" puts "Account xpub: #{kc.xpub}" puts "Account external xpub: #{kc.bip44_external_keychain.xpub}" puts "Index".ljust(10) + "External Address".ljust(40) + "Internal Address".ljust(40) range.each do |i| s = "" s << "#{i}".ljust(10) s << kc.bip44_external_keychain.derived_key(i).address.to_s.ljust(40) s << kc.bip44_internal_keychain.derived_key(i).address.to_s.ljust(40) puts s end end |
#seed ⇒ Object
17 18 19 |
# File 'lib/btcruby/mnemonic.rb', line 17 def seed @seed ||= make_seed(words: @words, password: @password) end |