Class: Tapyrus::PSTT::KeyOriginInfo
- Inherits:
-
Object
- Object
- Tapyrus::PSTT::KeyOriginInfo
- Extended by:
- KeyPath
- Includes:
- KeyPath
- Defined in:
- lib/tapyrus/pstt/key_origin_info.rb
Overview
The value of a BIP 32 derivation record: a master key fingerprint followed by a derivation path.
Instance Attribute Summary collapse
-
#fingerprint ⇒ Object
readonly
Returns the value of attribute fingerprint.
-
#key_paths ⇒ Object
readonly
Returns the value of attribute key_paths.
Class Method Summary collapse
-
.from_path(fingerprint, path) ⇒ Tapyrus::PSTT::KeyOriginInfo
Build from a derivation path string such as "m/44'/2377'/0'/0/0".
-
.parse_from_payload(payload) ⇒ Tapyrus::PSTT::KeyOriginInfo
Parse the value of a BIP 32 derivation record.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(fingerprint:, key_paths: []) ⇒ KeyOriginInfo
constructor
A new instance of KeyOriginInfo.
-
#path ⇒ String
The derivation path string.
- #to_payload ⇒ Object
Methods included from KeyPath
Constructor Details
#initialize(fingerprint:, key_paths: []) ⇒ KeyOriginInfo
Returns a new instance of KeyOriginInfo.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/tapyrus/pstt/key_origin_info.rb', line 18 def initialize(fingerprint:, key_paths: []) raise Error, "fingerprint must be 4 bytes." unless fingerprint.htb.bytesize == 4 # Each element occupies 4 bytes of the record. Array#pack truncates a larger value to its # lowest 32 bits without raising, which would turn a path this object was built with into # a different one once it is serialized. unless key_paths.all? { |index| index.is_a?(Integer) && index >= 0 && index <= 0xffffffff } raise Error, "Each derivation path element must be a 32-bit unsigned integer." end @fingerprint = fingerprint @key_paths = key_paths end |
Instance Attribute Details
#fingerprint ⇒ Object (readonly)
Returns the value of attribute fingerprint.
10 11 12 |
# File 'lib/tapyrus/pstt/key_origin_info.rb', line 10 def fingerprint @fingerprint end |
#key_paths ⇒ Object (readonly)
Returns the value of attribute key_paths.
14 15 16 |
# File 'lib/tapyrus/pstt/key_origin_info.rb', line 14 def key_paths @key_paths end |
Class Method Details
.from_path(fingerprint, path) ⇒ Tapyrus::PSTT::KeyOriginInfo
Build from a derivation path string such as "m/44'/2377'/0'/0/0".
45 46 47 |
# File 'lib/tapyrus/pstt/key_origin_info.rb', line 45 def self.from_path(fingerprint, path) new(fingerprint: fingerprint, key_paths: parse_key_path(path)) end |
.parse_from_payload(payload) ⇒ Tapyrus::PSTT::KeyOriginInfo
Parse the value of a BIP 32 derivation record.
33 34 35 36 37 38 39 |
# File 'lib/tapyrus/pstt/key_origin_info.rb', line 33 def self.parse_from_payload(payload) if payload.bytesize < 4 || ((payload.bytesize - 4) % 4) != 0 raise Error, "BIP 32 derivation value must be a 4-byte fingerprint followed by 32-bit path elements." end fingerprint, *key_paths = payload.unpack("H8V*") new(fingerprint: fingerprint, key_paths: key_paths) end |
Instance Method Details
#==(other) ⇒ Object
58 59 60 |
# File 'lib/tapyrus/pstt/key_origin_info.rb', line 58 def ==(other) other.is_a?(KeyOriginInfo) && to_payload == other.to_payload end |
#path ⇒ String
Returns the derivation path string.
54 55 56 |
# File 'lib/tapyrus/pstt/key_origin_info.rb', line 54 def path to_key_path(key_paths) end |
#to_payload ⇒ Object
49 50 51 |
# File 'lib/tapyrus/pstt/key_origin_info.rb', line 49 def to_payload fingerprint.htb + key_paths.pack("V*") end |