1from ..encoding.hexbytes import b2h 2 3from .Key import Key 4from .subpaths import subpaths_for_path_range 5 6 7class HierarchicalKey(Key): 8 def subkeys(self, path): 9 """ 10 A generalized form that can return multiple subkeys. 11 """ 12 for _ in subpaths_for_path_range(path, hardening_chars="'pH"): 13 yield self.subkey_for_path(_) 14 15 def ku_output_for_hk(self): 16 yield ("wallet_key", self.hwif(as_private=self.is_private()), None) 17 if self.is_private(): 18 yield ("public_version", self.hwif(as_private=False), None) 19 20 child_number = self.child_index() 21 if child_number >= 0x80000000: 22 wc = child_number - 0x80000000 23 child_index = "%dH (%d)" % (wc, child_number) 24 else: 25 child_index = "%d" % child_number 26 yield ("tree_depth", "%d" % self.tree_depth(), None) 27 yield ("fingerprint", b2h(self.fingerprint()), None) 28 yield ("parent_fingerprint", b2h(self.parent_fingerprint()), "parent f'print") 29 yield ("child_index", child_index, None) 30 yield ("chain_code", b2h(self.chain_code()), None) 31 32 yield ("private_key", "yes" if self.is_private() else "no", None) 33 34 def ku_output(self): 35 for _ in self.ku_output_for_hk(): 36 yield _ 37 38 for _ in super(HierarchicalKey, self).ku_output(): 39 yield _