Class: Bitcoin::PSBT::HDKeyPath

Inherits:
Object
  • Object
show all
Defined in:
lib/bitcoin/psbt/hd_key_path.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pubkey, info) ⇒ HDKeyPath

Returns a new instance of HDKeyPath.

Raises:

  • (ArgumentError)


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

#infoObject (readonly)

KeyOriginInfo



9
10
11
# File 'lib/bitcoin/psbt/hd_key_path.rb', line 9

def info
  @info
end

#pubkeyObject (readonly)

String



8
9
10
# File 'lib/bitcoin/psbt/hd_key_path.rb', line 8

def pubkey
  @pubkey
end

Instance Method Details

#to_hObject



26
27
28
# File 'lib/bitcoin/psbt/hd_key_path.rb', line 26

def to_h
  {pubkey: pubkey}.merge(info.to_h)
end

#to_payload(type = ) ⇒ String

generate payload which consist of pubkey and fingerprint, hd key path payload.

Returns:



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

#to_sObject



30
31
32
# File 'lib/bitcoin/psbt/hd_key_path.rb', line 30

def to_s
  to_h.to_s
end