From 8254a67341212e15657c53786871d03aee9a57b9 Mon Sep 17 00:00:00 2001 From: Adam Gibson Date: Mon, 22 Jan 2024 14:27:18 -0600 Subject: [PATCH] Update secp256k1 lib deps for pythonbitcointx1.1.5 Prior to this commit, code for scalar multiplication the module secp256k1_main in jmbitcoin relied on direct access to the secp256k1 linked library, but the API for accessing that object has now changed in python-bitcointx with version 1.1.5 (there is now a Secp256k1 data class with lib and ctx entries, see the Readme of the project for details). After this commit, we update our code for that API (but do not make functional changes to Joinmarket itself). --- pyproject.toml | 2 +- src/jmbitcoin/secp256k1_main.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index db73cd2..e17f7ae 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,7 +19,7 @@ dependencies = [ [project.optional-dependencies] jmbitcoin = [ - "python-bitcointx==1.1.4", + "python-bitcointx==1.1.5", ] jmclient = [ "argon2_cffi==21.3.0", diff --git a/src/jmbitcoin/secp256k1_main.py b/src/jmbitcoin/secp256k1_main.py index 652e35d..44204f9 100644 --- a/src/jmbitcoin/secp256k1_main.py +++ b/src/jmbitcoin/secp256k1_main.py @@ -5,8 +5,7 @@ from typing import List, Tuple, Union from jmbase import bintohex from bitcointx import base58 from bitcointx.core import Hash -from bitcointx.core.secp256k1 import _secp256k1 as secp_lib -from bitcointx.core.secp256k1 import secp256k1_context_verify +from bitcointx.core.secp256k1 import get_secp256k1 from bitcointx.core.key import CKey, CKeyBase, CPubKey from bitcointx.signmessage import BitcoinMessage @@ -14,9 +13,10 @@ from bitcointx.signmessage import BitcoinMessage # underlying bitcointx library, is to allow # multiplication of pubkeys by scalars, as is required # for PoDLE. +secp_obj = get_secp256k1() import ctypes -secp_lib.secp256k1_ec_pubkey_tweak_mul.restype = ctypes.c_int -secp_lib.secp256k1_ec_pubkey_tweak_mul.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_char_p] +secp_obj.lib.secp256k1_ec_pubkey_tweak_mul.restype = ctypes.c_int +secp_obj.lib.secp256k1_ec_pubkey_tweak_mul.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_char_p] #Required only for PoDLE calculation: N = 115792089237316195423570985008687907852837564279074904382605163141518161494337 @@ -159,8 +159,8 @@ def multiply(s: bytes, pub: bytes, return_serialized: bool = True) -> bytes: privkey_arg = ctypes.c_char_p(s) pubkey_buf = pub_obj._to_ctypes_char_array() - ret = secp_lib.secp256k1_ec_pubkey_tweak_mul( - secp256k1_context_verify, pubkey_buf, privkey_arg) + ret = secp_obj.lib.secp256k1_ec_pubkey_tweak_mul( + secp_obj.ctx.verify, pubkey_buf, privkey_arg) if ret != 1: assert ret == 0 raise ValueError('Multiplication failed')