Browse Source

Merge JoinMarket-Org/joinmarket-clientserver#1642: Update secp256k1 lib deps for python-bitcointx 1.1.5

8254a67341 Update secp256k1 lib deps for pythonbitcointx1.1.5 (Adam Gibson)

Pull request description:

  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).

ACKs for top commit:
  kristapsk:
    ACK 8254a67341. Tested by first just upgrading to python-bitcointx 1.1.5, which caused test failures, then applying all changes and tests passed.

Tree-SHA512: 371182be0a9abfd8bc020268c92f2de806f2d6b553d03f19dbb4768eee94a7fe8ef0bc441bf33ec5fa342529ee46f22971edaf46e8b9e3f96b6157316a69724e
master
Kristaps Kaupe 2 years ago
parent
commit
927ed0ab26
No known key found for this signature in database
GPG Key ID: 33E472FE870C7E5D
  1. 2
      pyproject.toml
  2. 12
      src/jmbitcoin/secp256k1_main.py

2
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",

12
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')

Loading…
Cancel
Save