Class: 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
-
#fingerprint ⇒ Object
Returns the value of attribute fingerprint.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#pubkey ⇒ Object
readonly
Returns the value of attribute pubkey.
Class Method Summary collapse
-
.parse_from_payload(pubkey, payload) ⇒ Bitcoin::PSBT::HDKeyPath
parse hd key path from payload.
Instance Method Summary collapse
-
#initialize(pubkey, fingerprint: nil, path: []) ⇒ HDKeyPath
constructor
A new instance of HDKeyPath.
-
#to_payload(type = ) ⇒ String
generate payload which consist of pubkey and fingerprint, hd key path payload.
Constructor Details
#initialize(pubkey, fingerprint: nil, path: []) ⇒ HDKeyPath
Returns a new instance of HDKeyPath.
12 13 14 15 16 |
# File 'lib/bitcoin/psbt/hd_key_path.rb', line 12 def initialize(pubkey, fingerprint: nil, path: []) @pubkey = pubkey @fingerprint = fingerprint @path = path end |
Instance Attribute Details
#fingerprint ⇒ Object
Returns the value of attribute fingerprint.
9 10 11 |
# File 'lib/bitcoin/psbt/hd_key_path.rb', line 9 def fingerprint @fingerprint end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
10 11 12 |
# File 'lib/bitcoin/psbt/hd_key_path.rb', line 10 def path @path end |
#pubkey ⇒ Object (readonly)
Returns the value of attribute pubkey.
8 9 10 |
# File 'lib/bitcoin/psbt/hd_key_path.rb', line 8 def pubkey @pubkey end |
Class Method Details
.parse_from_payload(pubkey, payload) ⇒ Bitcoin::PSBT::HDKeyPath
parse hd key path from payload.
22 23 24 25 26 27 |
# File 'lib/bitcoin/psbt/hd_key_path.rb', line 22 def self.parse_from_payload(pubkey, payload) 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, 'Invalid pubkey' unless pubkey.fully_valid_pubkey? self.new(pubkey.pubkey, fingerprint: payload[0...4].bth, path: payload[4..-1].unpack('I*')) end |
Instance Method Details
#to_payload(type = ) ⇒ String
generate payload which consist of pubkey and fingerprint, hd key path payload.
31 32 33 |
# File 'lib/bitcoin/psbt/hd_key_path.rb', line 31 def to_payload(type = PSBT_IN_TYPES[:bip32_derivation]) PSBT.serialize_to_vector(type, key: pubkey.htb, value: fingerprint.htb + path.pack('I*')) end |