Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions hwilib/descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,14 +673,14 @@ def _parse_descriptor(desc: str, ctx: '_ParseDescriptorContext', key_expr_index:
elif thresh > len(pubkeys):
raise ValueError("Multisig threshold cannot be larger than the number of keys; threshold is {} but only {} keys specified".format(thresh, len(pubkeys)))
if ctx == _ParseDescriptorContext.TOP and len(pubkeys) > 3:
raise ValueError("Cannot have {} pubkeys in bare multisig: only at most 3 pubkeys")
raise ValueError("Cannot have {} pubkeys in bare multisig: only at most 3 pubkeys".format(len(pubkeys)))
return MultisigDescriptor(pubkeys, thresh, is_sorted), key_expr_index
if func == "wpkh":
if not (ctx == _ParseDescriptorContext.TOP or ctx == _ParseDescriptorContext.P2SH):
raise ValueError("Can only have wpkh() at top level or inside sh()")
pubkey, expr, key_expr_index = parse_pubkey(expr, key_expr_index)
if expr:
raise ValueError("More than one pubkey in pkh descriptor")
raise ValueError("More than one pubkey in wpkh descriptor")
return WPKHDescriptor(pubkey), key_expr_index
if func == "sh":
if ctx != _ParseDescriptorContext.TOP:
Expand Down
14 changes: 14 additions & 0 deletions test/test_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,20 @@ def test_invalid_multipath_descriptors(self):
with self.assertRaisesRegex(ValueError, "invalid literal for int()"):
parse_descriptor("wpkh(xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB/<0;>/*)")

def test_wpkh_rejects_multiple_pubkeys(self):
pk1 = "0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"
pk2 = "02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5"
with self.assertRaisesRegex(ValueError, "More than one pubkey in wpkh descriptor"):
parse_descriptor("wpkh({},{})".format(pk1, pk2))

def test_bare_multisig_too_many_pubkeys_reports_count(self):
pk1 = "0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"
pk2 = "02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5"
pk3 = "02f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9"
pk4 = "02e493dbf1c10d80f3581e4904930b1404cc6c13900ee0758474fa94abe8c4cd13"
with self.assertRaisesRegex(ValueError, "Cannot have 4 pubkeys in bare multisig: only at most 3 pubkeys"):
parse_descriptor("multi(1,{},{},{},{})".format(pk1, pk2, pk3, pk4))

def test_valid_bip388_conversion(self):
def check(descriptor, keys, template):
d = parse_descriptor(descriptor)
Expand Down
Loading