Skip to content

Commit cdad492

Browse files
committed
Update to the new CCV specs
1 parent c955e97 commit cdad492

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

matt/contracts.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import hashlib
2+
13
from abc import ABC, abstractmethod
24
from dataclasses import dataclass
35
from enum import Enum
@@ -11,6 +13,19 @@
1113
from .btctools.segwit_addr import encode_segwit_address
1214

1315

16+
def tweak_embed_data(key: bytes, data: bytes) -> Optional[Tuple[bytes, Optional[bool]]]:
17+
"""
18+
Tweaks a key with the sha256 hash of the data, returning the tweaked key and whether the result had to be negated.
19+
If the data is empty, the key is returned as is.
20+
"""
21+
22+
if len(data) == 0:
23+
return key, None
24+
25+
data_tweak = hashlib.sha256(key + data).digest()
26+
return tweak_add_pubkey(key, data_tweak)
27+
28+
1429
class AbstractContract:
1530
pass
1631

@@ -317,9 +332,7 @@ def get_taptree_merkle_root(self) -> bytes:
317332
return self.get_tr_info(b'\0'*32).merkle_root
318333

319334
def get_tr_info(self, data: bytes) -> TaprootInfo:
320-
assert len(data) == 32
321-
322-
internal_pubkey, _ = tweak_add_pubkey(self.naked_internal_pubkey, data)
335+
internal_pubkey, _ = tweak_embed_data(self.naked_internal_pubkey, data)
323336

324337
return script.taproot_construct(internal_pubkey, self.get_scripts())
325338

0 commit comments

Comments
 (0)