File tree 1 file changed +16
-3
lines changed
1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change
1
+ import hashlib
2
+
1
3
from abc import ABC , abstractmethod
2
4
from dataclasses import dataclass
3
5
from enum import Enum
11
13
from .btctools .segwit_addr import encode_segwit_address
12
14
13
15
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
+
14
29
class AbstractContract :
15
30
pass
16
31
@@ -317,9 +332,7 @@ def get_taptree_merkle_root(self) -> bytes:
317
332
return self .get_tr_info (b'\0 ' * 32 ).merkle_root
318
333
319
334
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 )
323
336
324
337
return script .taproot_construct (internal_pubkey , self .get_scripts ())
325
338
You can’t perform that action at this time.
0 commit comments