Class: MoneyTree::Address
- Inherits:
-
Object
- Object
- MoneyTree::Address
- Defined in:
- lib/money-tree/address.rb
Instance Attribute Summary collapse
-
#private_key ⇒ Object
readonly
Returns the value of attribute private_key.
-
#public_key ⇒ Object
readonly
Returns the value of attribute public_key.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Address
constructor
A new instance of Address.
- #to_bech32(network: :bitcoin) ⇒ Object
- #to_p2wpkh_p2sh(network: :bitcoin) ⇒ Object
- #to_s(network: :bitcoin) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Address
Returns a new instance of Address.
6 7 8 9 10 |
# File 'lib/money-tree/address.rb', line 6 def initialize(opts = {}) private_key = opts.delete(:private_key) @private_key = PrivateKey.new({ key: private_key }.merge(opts)) @public_key = PublicKey.new(@private_key, opts) end |
Instance Attribute Details
#private_key ⇒ Object (readonly)
Returns the value of attribute private_key.
3 4 5 |
# File 'lib/money-tree/address.rb', line 3 def private_key @private_key end |
#public_key ⇒ Object (readonly)
Returns the value of attribute public_key.
4 5 6 |
# File 'lib/money-tree/address.rb', line 4 def public_key @public_key end |
Instance Method Details
#to_bech32(network: :bitcoin) ⇒ Object
16 17 18 19 20 |
# File 'lib/money-tree/address.rb', line 16 def to_bech32(network: :bitcoin) hrp = NETWORKS[network][:human_readable_part] witprog = @public_key.to_ripemd160 Support.to_serialized_bech32(hrp, witprog) end |
#to_p2wpkh_p2sh(network: :bitcoin) ⇒ Object
22 23 24 |
# File 'lib/money-tree/address.rb', line 22 def to_p2wpkh_p2sh(network: :bitcoin) @public_key.to_p2wpkh_p2sh(network: network) end |
#to_s(network: :bitcoin) ⇒ Object
12 13 14 |
# File 'lib/money-tree/address.rb', line 12 def to_s(network: :bitcoin) @public_key.to_s(network: network) end |