Class: Bitcoin::BIP85Entropy
- Inherits:
-
Object
- Object
- Bitcoin::BIP85Entropy
- 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
-
#root_key ⇒ Object
readonly
hex format.
Class Method Summary collapse
-
.from_base58(base58) ⇒ Bitcoin::BIP85Entropy
Import root key.
Instance Method Summary collapse
-
#derive(path) ⇒ Tuple(String, Object)
derive entropy.
Methods included from KeyPath
Instance Attribute Details
#root_key ⇒ Object (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.
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
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 |