2929from typing import Optional
3030
3131from bitcointx .core .secp256k1 import (
32- _secp256k1 , COMPACT_SIGNATURE_SIZE , secp256k1_context_verify
32+ get_secp256k1 , COMPACT_SIGNATURE_SIZE
3333)
3434
3535
@@ -47,9 +47,11 @@ def ecdsa_signature_parse_der_lax(laxinput: bytes) -> Optional[bytes]: # noqa
4747
4848 sig = ctypes .create_string_buffer (COMPACT_SIGNATURE_SIZE )
4949
50+ secp256k1 = get_secp256k1 ()
51+
5052 # Hack to initialize sig with a correctly-parsed but invalid signature. */
51- _secp256k1 .secp256k1_ecdsa_signature_parse_compact (
52- secp256k1_context_verify , sig , bytes (tmpsig ))
53+ secp256k1 . lib .secp256k1_ecdsa_signature_parse_compact (
54+ secp256k1 . ctx . verify , sig , bytes (tmpsig ))
5355
5456 # Sequence tag byte
5557 if pos == inputlen or laxinput [pos ] != 0x30 :
@@ -173,15 +175,15 @@ def ecdsa_signature_parse_der_lax(laxinput: bytes) -> Optional[bytes]: # noqa
173175 tmpsig [64 - slen :64 ] = laxinput [spos :spos + slen ]
174176
175177 if not overflow :
176- parse_result = _secp256k1 .secp256k1_ecdsa_signature_parse_compact (
177- secp256k1_context_verify , sig , bytes (tmpsig ))
178+ parse_result = secp256k1 . lib .secp256k1_ecdsa_signature_parse_compact (
179+ secp256k1 . ctx . verify , sig , bytes (tmpsig ))
178180 overflow = int (not parse_result )
179181
180182 if overflow :
181183 # Overwrite the result again with a correctly-parsed but invalid
182184 # signature if parsing failed.
183185 tmpsig = bytearray ([0 for _ in range (64 )])
184- _secp256k1 .secp256k1_ecdsa_signature_parse_compact (
185- secp256k1_context_verify , sig , bytes (tmpsig ))
186+ secp256k1 . lib .secp256k1_ecdsa_signature_parse_compact (
187+ secp256k1 . ctx . verify , sig , bytes (tmpsig ))
186188
187189 return sig .raw
0 commit comments