Class: MoneyTree::Master
Defined Under Namespace
Modules: SeedGeneration
Constant Summary collapse
- HD_WALLET_BASE_KEY =
"Bitcoin seed"
- RANDOM_SEED_SIZE =
32
Constants inherited from Node
Constants included from Support
Support::BASE58_CHARS, Support::INT32_MAX, Support::INT64_MAX
Instance Attribute Summary collapse
-
#seed ⇒ Object
readonly
Returns the value of attribute seed.
-
#seed_hash ⇒ Object
readonly
Returns the value of attribute seed_hash.
Attributes inherited from Node
#chain_code, #depth, #index, #is_private, #parent, #private_key, #public_key
Instance Method Summary collapse
- #generate_seed ⇒ Object
- #generate_seed_hash(seed) ⇒ Object
-
#initialize(opts = {}) ⇒ Master
constructor
A new instance of Master.
- #is_private? ⇒ Boolean
- #seed_hex ⇒ Object
- #seed_valid?(seed_hash) ⇒ Boolean
- #set_seeded_keys ⇒ Object
Methods inherited from Node
#chain_code_hex, #depth_hex, #derive_parent_node, #derive_private_key, #derive_public_key, from_bip32, #i_as_bytes, #index_hex, #left_from_hash, #negative?, #node_for_path, #parent_fingerprint, #parse_index, parse_out_key, #private_derivation_message, #public_derivation_message, #right_from_hash, #strip_private_info!, #subnode, #to_address, #to_bech32_address, #to_bip32, #to_fingerprint, #to_identifier, #to_p2wpkh_p2sh, #to_serialized_hex
Methods included from Support
#base58_to_int, #bytes_to_hex, #bytes_to_int, #convert_p2wpkh_p2sh, #custom_hash_160, #decode_base58, #decode_base64, #digestify, #encode_base58, #encode_base64, #encode_p2wpkh_p2sh, #from_serialized_base58, #hex_to_bytes, #hex_to_int, #hmac_sha512, #hmac_sha512_hex, #int_to_base58, #int_to_bytes, #int_to_hex, #ripemd160, #sha256, #to_serialized_base58, #to_serialized_bech32
Constructor Details
#initialize(opts = {}) ⇒ Master
Returns a new instance of Master.
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
# File 'lib/money-tree/node.rb', line 265 def initialize(opts = {}) @depth = 0 @index = 0 opts[:seed] = [opts[:seed_hex]].pack("H*") if opts[:seed_hex] if opts[:seed] @seed = opts[:seed] @seed_hash = generate_seed_hash(@seed) raise SeedGeneration::ImportError unless seed_valid?(@seed_hash) set_seeded_keys elsif opts[:private_key] || opts[:public_key] raise ImportError, "chain code required" unless opts[:chain_code] @chain_code = opts[:chain_code] if opts[:private_key] @private_key = opts[:private_key] @public_key = MoneyTree::PublicKey.new @private_key else opts[:public_key] @public_key = if opts[:public_key].is_a?(MoneyTree::PublicKey) opts[:public_key] else MoneyTree::PublicKey.new(opts[:public_key]) end end else generate_seed set_seeded_keys end end |
Instance Attribute Details
#seed ⇒ Object (readonly)
Returns the value of attribute seed.
263 264 265 |
# File 'lib/money-tree/node.rb', line 263 def seed @seed end |
#seed_hash ⇒ Object (readonly)
Returns the value of attribute seed_hash.
263 264 265 |
# File 'lib/money-tree/node.rb', line 263 def seed_hash @seed_hash end |
Instance Method Details
#generate_seed ⇒ Object
296 297 298 299 300 |
# File 'lib/money-tree/node.rb', line 296 def generate_seed @seed = OpenSSL::Random.random_bytes(32) @seed_hash = generate_seed_hash(@seed) raise SeedGeneration::ValidityError unless seed_valid?(@seed_hash) end |
#generate_seed_hash(seed) ⇒ Object
302 303 304 |
# File 'lib/money-tree/node.rb', line 302 def generate_seed_hash(seed) hmac_sha512 HD_WALLET_BASE_KEY, seed end |
#is_private? ⇒ Boolean
292 293 294 |
# File 'lib/money-tree/node.rb', line 292 def is_private? true end |
#seed_hex ⇒ Object
318 319 320 |
# File 'lib/money-tree/node.rb', line 318 def seed_hex bytes_to_hex(seed) end |