Class: Bitcoin::Wallet::DeterministicKeyStore
- Inherits:
-
Object
- Object
- Bitcoin::Wallet::DeterministicKeyStore
- Defined in:
- lib/bitcoin/wallet/keystore.rb
Overview
Deterministic keystore.
Instance Attribute Summary collapse
-
#generator ⇒ Object
readonly
Returns the value of attribute generator.
Instance Method Summary collapse
-
#export(addr) ⇒ Object
Export key for given
addr
to base58. -
#initialize(config) ⇒ DeterministicKeyStore
constructor
Initialize keystore.
-
#key(addr) ⇒ Object
Get key for given
addr
. -
#keys ⇒ Object
List all keys upto configured limit.
-
#new_key ⇒ Object
Get new key (actually just increase the key limit).
Constructor Details
#initialize(config) ⇒ DeterministicKeyStore
Initialize keystore.
- config
-
Hash of settings (=> 1, :seed => …, :nonce => …)
174 175 176 177 178 |
# File 'lib/bitcoin/wallet/keystore.rb', line 174 def initialize config @config = Hash[config.map{|k,v|[k.to_sym,v]}] @config[:keys] = (@config[:keys] || 1).to_i @generator = Bitcoin::Wallet::KeyGenerator.new(@config[:seed], @config[:nonce]) end |
Instance Attribute Details
#generator ⇒ Object (readonly)
Returns the value of attribute generator.
170 171 172 |
# File 'lib/bitcoin/wallet/keystore.rb', line 170 def generator @generator end |
Instance Method Details
#export(addr) ⇒ Object
Export key for given addr
to base58. (See Bitcoin::Key.to_base58)
201 202 203 |
# File 'lib/bitcoin/wallet/keystore.rb', line 201 def export(addr) key(addr).to_base58 rescue nil end |
#key(addr) ⇒ Object
Get key for given addr
.
186 187 188 189 190 191 |
# File 'lib/bitcoin/wallet/keystore.rb', line 186 def key(addr) 1.upto(@config[:keys].to_i).map do |i| key = @generator.get_key(i) return key if key.addr == addr end end |
#keys ⇒ Object
List all keys upto configured limit.
181 182 183 |
# File 'lib/bitcoin/wallet/keystore.rb', line 181 def keys 1.upto(@config[:keys].to_i).map {|i| @generator.get_key(i) } end |
#new_key ⇒ Object
Get new key (actually just increase the key limit).
194 195 196 197 |
# File 'lib/bitcoin/wallet/keystore.rb', line 194 def new_key @config[:keys] += 1 @generator.get_key(@config[:keys]) end |