Method: Bitcoin::Wallet::KeyGenerator#initialize

Defined in:
lib/bitcoin/wallet/keygenerator.rb

#initialize(seed = nil, nonce = nil, target = nil) ⇒ KeyGenerator

Initialize key generator with optional seed and nonce and target.

seed

the seed data for the keygenerator (default: random)

nonce

the nonce required to satisfy the target (default: computed)

target

custom difficulty target (default: DEFAULT_TARGET)

Example:

g = KeyGenerator.new # random seed, computed nonce, default target
KeyGenerator.new(g.seed)
KeyGenerator.new(g.seed, g.nonce)
g.get_key(0) #=> <Bitcoin::Key>

Note: When initializing without seed, you should obviously save the seed once it is generated. Saving the nonce is optional; it only saves time.



31
32
33
34
35
# File 'lib/bitcoin/wallet/keygenerator.rb', line 31

def initialize seed = nil, nonce = nil, target = nil
  @seed = seed || OpenSSL::Random.random_bytes(64)
  @target = target || DEFAULT_TARGET
  @nonce = check_nonce(nonce)
end