Skip to content

Commit

Permalink
Merge #664: descriptor.py: fix PubkeyProvider.get_pubkey_bytes for ra…
Browse files Browse the repository at this point in the history
…nged desc

a1045bc descriptor.py: fix PubkeyProvider.get_pubkey_bytes for ranged desc (SomberNight)

Pull request description:

  To trigger bug:
  ```py
  >>> from hwilib.descriptor import parse_descriptor
  >>> b = parse_descriptor("wsh(multi(1,xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB/1/0/*,xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH/0/0/*))")
  >>> b.expand(3).output_script.hex()
  Traceback (most recent call last):
    File "/home/user/wspace/HWI/hwilib/key.py", line 361, in parse_path
      return [str_to_harden(x) for x in n]
    File "/home/user/wspace/HWI/hwilib/key.py", line 361, in <listcomp>
      return [str_to_harden(x) for x in n]
    File "/home/user/wspace/HWI/hwilib/key.py", line 358, in str_to_harden
      return int(x)
  ValueError: invalid literal for int() with base 10: '*3'

  During handling of the above exception, another exception occurred:

  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/home/user/wspace/HWI/hwilib/descriptor.py", line 385, in expand
      witness_script, _, _ = self.subdescriptors[0].expand(pos)
    File "/home/user/wspace/HWI/hwilib/descriptor.py", line 340, in expand
      der_pks = [p.get_pubkey_bytes(pos) for p in self.pubkeys]
    File "/home/user/wspace/HWI/hwilib/descriptor.py", line 340, in <listcomp>
      der_pks = [p.get_pubkey_bytes(pos) for p in self.pubkeys]
    File "/home/user/wspace/HWI/hwilib/descriptor.py", line 170, in get_pubkey_bytes
      path = parse_path(path_str)
    File "/home/user/wspace/HWI/hwilib/key.py", line 363, in parse_path
      raise ValueError("Invalid BIP32 path", nstr)
  ValueError: ('Invalid BIP32 path', '*3')
  ```

ACKs for top commit:
  achow101:
    ACK a1045bc

Tree-SHA512: 6d0aaeb8ce2bc220de3b47ca31994ead2caea7867298a8008c06a6d8ffa20b4190cc1bf2174ffabcc70dab6f0191d09c445e429bf6988b37039f40e4bdc9e45c
  • Loading branch information
achow101 committed Feb 13, 2023
2 parents 5f300d3 + a1045bc commit 092cc1c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion hwilib/descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def get_pubkey_bytes(self, pos: int) -> bytes:
if self.deriv_path is not None:
path_str = self.deriv_path[1:]
if path_str[-1] == "*":
path_str = path_str[-1] + str(pos)
path_str = path_str[:-1] + str(pos)
path = parse_path(path_str)
child_key = self.extkey.derive_pub_path(path)
return child_key.pubkey
Expand Down

0 comments on commit 092cc1c

Please sign in to comment.