Class: Bitcoin::PSBT::HDKeyPath
- Inherits:
-
Object
- Object
- Bitcoin::PSBT::HDKeyPath
- Defined in:
- lib/bitcoin/psbt/hd_key_path.rb
Overview
HD Key path data structure. see github.com/bitcoin/bips/blob/master/bip-0174.mediawiki#Specification
Instance Attribute Summary collapse
-
#info ⇒ Object
readonly
KeyOriginInfo.
-
#pubkey ⇒ Object
readonly
String.
Instance Method Summary collapse
-
#initialize(pubkey, info) ⇒ HDKeyPath
constructor
A new instance of HDKeyPath.
- #to_h ⇒ Object
-
#to_payload(type = ) ⇒ String
generate payload which consist of pubkey and fingerprint, hd key path payload.
- #to_s ⇒ Object
Constructor Details
permalink #initialize(pubkey, info) ⇒ HDKeyPath
Returns a new instance of HDKeyPath.
11 12 13 14 15 16 17 18 |
# File 'lib/bitcoin/psbt/hd_key_path.rb', line 11 def initialize(pubkey, info) pubkey = pubkey.encoding == Encoding::ASCII_8BIT ? pubkey : pubkey.htb raise ArgumentError, 'Size of key was not the expected size for the type BIP32 keypath.' unless [Bitcoin::Key::PUBLIC_KEY_SIZE, Bitcoin::Key::COMPRESSED_PUBLIC_KEY_SIZE].include?(pubkey.bytesize) pubkey = Bitcoin::Key.new(pubkey: pubkey.bth) raise ArgumentError, Errors::Messages::INVALID_PUBLIC_KEY unless pubkey.fully_valid_pubkey? @pubkey = pubkey.pubkey @info = info end |
Instance Attribute Details
permalink #info ⇒ Object (readonly)
KeyOriginInfo
9 10 11 |
# File 'lib/bitcoin/psbt/hd_key_path.rb', line 9 def info @info end |
permalink #pubkey ⇒ Object (readonly)
String
8 9 10 |
# File 'lib/bitcoin/psbt/hd_key_path.rb', line 8 def pubkey @pubkey end |
Instance Method Details
permalink #to_h ⇒ Object
[View source]
26 27 28 |
# File 'lib/bitcoin/psbt/hd_key_path.rb', line 26 def to_h {pubkey: pubkey}.merge(info.to_h) end |
permalink #to_payload(type = ) ⇒ String
generate payload which consist of pubkey and fingerprint, hd key path payload.
22 23 24 |
# File 'lib/bitcoin/psbt/hd_key_path.rb', line 22 def to_payload(type = PSBT_IN_TYPES[:bip32_derivation]) PSBT.serialize_to_vector(type, key: pubkey.htb, value: info.to_payload) end |
permalink #to_s ⇒ Object
[View source]
30 31 32 |
# File 'lib/bitcoin/psbt/hd_key_path.rb', line 30 def to_s to_h.to_s end |