Class: Bitcoin::BIP85Entropy

Inherits:
Object
  • Object
show all
Includes:
KeyPath
Defined in:
lib/bitcoin/bip85_entropy.rb

Overview

Deterministic Entropy From BIP32 Keychains github.com/bitcoin/bips/blob/master/bip-0085.mediawiki

Constant Summary collapse

BIP85_PATH =
83696968 + HARDENED_THRESHOLD

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from KeyPath

#parse_key_path, #to_key_path

Instance Attribute Details

#root_keyObject (readonly)

hex format



11
12
13
# File 'lib/bitcoin/bip85_entropy.rb', line 11

def root_key
  @root_key
end

Class Method Details

.from_base58(base58) ⇒ Bitcoin::BIP85Entropy

Import root key.

Parameters:

  • base58 (String)

    master bip32 root key.

Returns:



16
17
18
19
# File 'lib/bitcoin/bip85_entropy.rb', line 16

def self.from_base58(base58)
  key = Bitcoin::ExtKey.from_base58(base58)
  self.new(key)
end

Instance Method Details

#derive(path) ⇒ Tuple(String, Object)

derive entropy

Parameters:

  • path (String)

    derive path.

Returns:

  • (Tuple(String, Object))

    a tuple of entropy with hex format and results depending the application.

Raises:

  • (ArgumentError)


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/bitcoin/bip85_entropy.rb', line 24

def derive(path)
  raise ArgumentError, "Invalid BIP85 path format." unless path.start_with?("m/83696968'")
  derived_key = root_key
  parse_key_path(path).each{|num| derived_key = derived_key.derive(num)}
  derived_key = derived_key.priv
  entropy = Bitcoin.hmac_sha512("bip-entropy-from-k", derived_key.htb).bth
  app_no = path.split('/')[2]
  case app_no
  when "39'"
    bip39_entropy(path, entropy)
  when "2'"
    hd_seed_entropy(entropy)
  when "32'"
    xprv_entropy(entropy)
  else
    [entropy, entropy]
  end
end