Class: MoneyTree::Master
Defined Under Namespace
Modules: SeedGeneration
Constant Summary collapse
- HD_WALLET_BASE_KEY =
"Bitcoin seed"
- RANDOM_SEED_SIZE =
32
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_private_key, #derive_public_key, from_bip32, from_serialized_address, #i_as_bytes, #index_hex, #left_from_hash, #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_bip32, #to_fingerprint, #to_identifier, #to_serialized_address, #to_serialized_hex
Methods included from Support
#base58_to_int, #bytes_to_hex, #bytes_to_int, #decode_base58, #decode_base64, #digestify, #encode_base58, #encode_base64, #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
Constructor Details
#initialize(opts = {}) ⇒ Master
Returns a new instance of Master.
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/money-tree/node.rb', line 244 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.
242 243 244 |
# File 'lib/money-tree/node.rb', line 242 def seed @seed end |
#seed_hash ⇒ Object (readonly)
Returns the value of attribute seed_hash.
242 243 244 |
# File 'lib/money-tree/node.rb', line 242 def seed_hash @seed_hash end |
Instance Method Details
#generate_seed ⇒ Object
276 277 278 279 280 |
# File 'lib/money-tree/node.rb', line 276 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
282 283 284 |
# File 'lib/money-tree/node.rb', line 282 def generate_seed_hash(seed) hmac_sha512 HD_WALLET_BASE_KEY, seed end |
#is_private? ⇒ Boolean
272 273 274 |
# File 'lib/money-tree/node.rb', line 272 def is_private? true end |
#seed_hex ⇒ Object
298 299 300 |
# File 'lib/money-tree/node.rb', line 298 def seed_hex bytes_to_hex(seed) end |