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
3 changes: 3 additions & 0 deletions src/embit/descriptor/descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def __init__(
# make sure all keys are either taproot or not
for k in self.keys:
k.taproot = taproot
# BIP-386: uncompressed keys are not allowed in tr()
if self.taproot and not getattr(k.key, "compressed", True):
Comment thread
jdlcdl marked this conversation as resolved.
Resolved
raise DescriptorError("Uncompressed keys are not allowed in tr()")

@property
def script_len(self):
Expand Down
35 changes: 34 additions & 1 deletion tests/tests/test_descriptor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from unittest import TestCase
from binascii import hexlify
from binascii import hexlify, unhexlify
from embit.descriptor import Descriptor, Key
from embit.descriptor.arguments import KeyHash, Number
from embit.descriptor.miniscript import OPERATORS, WRAPPERS
Expand Down Expand Up @@ -248,6 +248,39 @@ def test_descriptor_from_string_validation(self):
with self.assertRaises(DescriptorError):
Descriptor.from_string(d)

def test_tr_uncompressed_key(self):
Comment thread
jdlcdl marked this conversation as resolved.
Resolved
U = (
"04c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee51ae"
"168fea63dc339a3c58419466ceaeef7f632653266d0e1236431a950cfe52a"
)
UWIF = "5HpjE2Hs7vjU4SN3YyPQCdhzCu92WoEeuE6PWNuiPyTu3ESGnzn"
C = "0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"
X = "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"
# BIP 386: uncompressed keys are not allowed in tr()
for d in [
"tr(%s)" % U,
"tr(%s)" % UWIF,
"tr(%s,pk(%s))" % (C, U),
"tr(%s,multi_a(1,%s))" % (C, U),
"tr(%s,{pk(%s),pk(%s)})" % (C, C, U),
"tr(%s,{pk(%s),{pk(%s),multi_a(1,%s)}})" % (C, C, C, U),
]:
self.assertRaises(DescriptorError, Descriptor.from_string, d)

# direct construction with uncompressed key must also fail
ukey = Key(ec.PublicKey.parse(unhexlify(U)))
self.assertRaises(DescriptorError, Descriptor, key=ukey, taproot=True)

# compressed and x-only keys are valid
for d in [
"tr(%s)" % C,
"tr(%s)" % X,
"tr(%s,pk(%s))" % (C, C),
"tr(%s,multi_a(1,%s))" % (C, C),
"tr(%s,{pk(%s),pk(%s)})" % (C, C, X),
]:
Descriptor.from_string(d)

def test_keys(self):
keys = [
"[f45912ab/44h/12/32h]xpub6F6wWxm8F64iBHNhyaoh3QKCuuMUY5pfPPr1H1WuZXUXeXtZ21qjFN5ykaqnLL1jtPEFB9d94CyZrcYWKVdSiJKQ6mLGEB5sfrGFBpg6wgA",
Expand Down
Loading