Skip to content

Commit

Permalink
Get rid of secp256k1 python packet
Browse files Browse the repository at this point in the history
  • Loading branch information
igorsereda committed Jul 12, 2024
1 parent 4ba8e1d commit 060883b
Show file tree
Hide file tree
Showing 7 changed files with 231 additions and 248 deletions.
14 changes: 2 additions & 12 deletions michelson-kernel.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,7 @@ RUN apk add --update --no-cache \
python3-dev \
libffi-dev \
gmp-dev \
libsodium-dev \
libsecp256k1-dev

RUN mkdir /tmp/secp256k1 \
&& cd /tmp \
&& wget https://github.com/bitcoin-core/secp256k1/archive/refs/tags/v0.2.0.tar.gz -O /tmp/secp256k1.tar.gz \
&& tar -xzf /tmp/secp256k1.tar.gz -C /tmp/secp256k1 --strip-components=1 \
&& cd /tmp/secp256k1 \
&& ./autogen.sh \
&& ./configure
libsodium-dev

RUN python -m venv --without-pip --system-site-packages /opt/pytezos \
&& mkdir -p /opt/pytezos/src/pytezos/ \
Expand All @@ -35,8 +26,7 @@ FROM python:3.12-alpine3.17 AS build-image
RUN apk add --update --no-cache \
binutils \
gmp-dev \
libsodium-dev \
libsecp256k1-dev
libsodium-dev

RUN adduser -D pytezos
USER pytezos
Expand Down
384 changes: 192 additions & 192 deletions poetry.lock

Large diffs are not rendered by default.

16 changes: 3 additions & 13 deletions pytezos.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,7 @@ RUN apk add --update --no-cache \
python3-dev \
libffi-dev \
gmp-dev \
libsodium-dev \
libsecp256k1-dev

RUN mkdir /tmp/secp256k1 \
&& cd /tmp \
&& wget https://github.com/bitcoin-core/secp256k1/archive/refs/tags/v0.2.0.tar.gz -O /tmp/secp256k1.tar.gz \
&& tar -xzf /tmp/secp256k1.tar.gz -C /tmp/secp256k1 --strip-components=1 \
&& cd /tmp/secp256k1 \
&& ./autogen.sh \
&& ./configure
libsodium-dev

RUN python -m venv --without-pip --system-site-packages /opt/pytezos \
&& mkdir -p /opt/pytezos/src/pytezos/ \
Expand All @@ -35,8 +26,7 @@ FROM python:3.12-alpine3.17 AS build-image
RUN apk add --update --no-cache \
binutils \
gmp-dev \
libsodium-dev \
libsecp256k1-dev
libsodium-dev

RUN adduser -D pytezos
USER pytezos
Expand All @@ -46,4 +36,4 @@ WORKDIR /home/pytezos/
ENTRYPOINT ["python"]

COPY --chown=pytezos --from=compile-image /opt/pytezos /opt/pytezos
COPY --chown=pytezos . /opt/pytezos
COPY --chown=pytezos . /opt/pytezos
24 changes: 12 additions & 12 deletions requirements.dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ appnope==0.1.4 ; python_full_version >= "3.8.1" and python_version < "3.13" and
argon2-cffi-bindings==21.2.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
argon2-cffi==23.1.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
arrow==1.3.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
asn1crypto==1.5.1 ; python_full_version >= "3.8.1" and python_version < "3.13"
asttokens==2.4.1 ; python_full_version >= "3.8.1" and python_version < "3.13"
attrs==23.2.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
babel==2.15.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
Expand All @@ -14,14 +15,15 @@ black==24.4.2 ; python_full_version >= "3.8.1" and python_version < "3.13"
bleach==6.1.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
cached-property==1.5.2 ; python_full_version >= "3.8.1" and python_version < "3.13"
cattrs==23.2.3 ; python_full_version >= "3.8.1" and python_version < "3.13"
certifi==2024.6.2 ; python_full_version >= "3.8.1" and python_version < "3.13"
certifi==2024.7.4 ; python_full_version >= "3.8.1" and python_version < "3.13"
cffi==1.16.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
chardet==5.2.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
charset-normalizer==3.3.2 ; python_full_version >= "3.8.1" and python_version < "3.13"
click==8.1.7 ; python_full_version >= "3.8.1" and python_version < "3.13"
coincurve==20.0.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
colorama==0.4.6 ; python_full_version >= "3.8.1" and python_version < "3.13" and (platform_system == "Windows" or sys_platform == "win32")
comm==0.2.2 ; python_full_version >= "3.8.1" and python_version < "3.13"
coverage[toml]==7.5.4 ; python_full_version >= "3.8.1" and python_version < "3.13"
coverage[toml]==7.6.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
cryptography==42.0.8 ; python_full_version >= "3.8.1" and python_version < "3.13"
cytoolz==0.12.3 ; python_full_version >= "3.8.1" and python_version < "3.13" and implementation_name == "cpython"
debugpy==1.8.2 ; python_full_version >= "3.8.1" and python_version < "3.13"
Expand All @@ -33,7 +35,7 @@ docker==7.1.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
docutils==0.20.1 ; python_full_version >= "3.8.1" and python_version < "3.13"
entrypoints==0.4 ; python_full_version >= "3.8.1" and python_version < "3.13"
eth-hash==0.7.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
eth-typing==4.3.1 ; python_full_version >= "3.8.1" and python_version < "3.13"
eth-typing==4.4.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
eth-utils==4.1.1 ; python_full_version >= "3.8.1" and python_version < "3.13"
exceptiongroup==1.2.1 ; python_full_version >= "3.8.1" and python_version < "3.11"
execnet==2.1.1 ; python_full_version >= "3.8.1" and python_version < "3.13"
Expand All @@ -46,7 +48,7 @@ imagesize==1.4.1 ; python_full_version >= "3.8.1" and python_version < "3.13"
importlib-metadata==8.0.0 ; python_full_version >= "3.8.1" and python_version < "3.10"
importlib-resources==6.4.0 ; python_full_version >= "3.8.1" and python_version < "3.9"
iniconfig==2.0.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
ipykernel==6.29.4 ; python_full_version >= "3.8.1" and python_version < "3.13"
ipykernel==6.29.5 ; python_full_version >= "3.8.1" and python_version < "3.13"
ipython-genutils==0.2.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
ipython==8.12.3 ; python_full_version >= "3.8.1" and python_version < "3.13"
isoduration==20.11.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
Expand All @@ -55,8 +57,8 @@ jedi==0.19.1 ; python_full_version >= "3.8.1" and python_version < "3.13"
jinja2==3.1.4 ; python_full_version >= "3.8.1" and python_version < "3.13"
jsonpointer==3.0.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
jsonschema-specifications==2023.12.1 ; python_full_version >= "3.8.1" and python_version < "3.13"
jsonschema==4.22.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
jsonschema[format-nongpl]==4.22.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
jsonschema==4.23.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
jsonschema[format-nongpl]==4.23.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
jupyter-client==7.4.9 ; python_full_version >= "3.8.1" and python_version < "3.13"
jupyter-core==5.7.2 ; python_full_version >= "3.8.1" and python_version < "3.13"
jupyter-events==0.10.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
Expand Down Expand Up @@ -112,11 +114,9 @@ referencing==0.35.1 ; python_full_version >= "3.8.1" and python_version < "3.13"
requests==2.32.3 ; python_full_version >= "3.8.1" and python_version < "3.13"
rfc3339-validator==0.1.4 ; python_full_version >= "3.8.1" and python_version < "3.13"
rfc3986-validator==0.1.1 ; python_full_version >= "3.8.1" and python_version < "3.13"
rpds-py==0.18.1 ; python_full_version >= "3.8.1" and python_version < "3.13"
ruff==0.5.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
secp256k1==0.14.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
rpds-py==0.19.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
ruff==0.5.1 ; python_full_version >= "3.8.1" and python_version < "3.13"
send2trash==1.8.3 ; python_full_version >= "3.8.1" and python_version < "3.13"
setuptools==70.1.1 ; python_full_version >= "3.8.1" and python_version < "3.13"
simple-bson==0.0.3 ; python_full_version >= "3.8.1" and python_version < "3.13"
simplejson==3.19.2 ; python_full_version >= "3.8.1" and python_version < "3.13"
six==1.16.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
Expand Down Expand Up @@ -148,8 +148,8 @@ tqdm==4.66.4 ; python_full_version >= "3.8.1" and python_version < "3.13"
traitlets==5.14.3 ; python_full_version >= "3.8.1" and python_version < "3.13"
types-python-dateutil==2.9.0.20240316 ; python_full_version >= "3.8.1" and python_version < "3.13"
types-pyyaml==6.0.12.20240311 ; python_full_version >= "3.8.1" and python_version < "3.13"
types-requests==2.32.0.20240622 ; python_full_version >= "3.8.1" and python_version < "3.13"
types-setuptools==70.1.0.20240627 ; python_full_version >= "3.8.1" and python_version < "3.13"
types-requests==2.32.0.20240712 ; python_full_version >= "3.8.1" and python_version < "3.13"
types-setuptools==70.3.0.20240710 ; python_full_version >= "3.8.1" and python_version < "3.13"
types-simplejson==3.19.0.20240310 ; python_full_version >= "3.8.1" and python_version < "3.13"
types-tabulate==0.9.0.20240106 ; python_full_version >= "3.8.1" and python_version < "3.13"
typing-extensions==4.12.2 ; python_full_version >= "3.8.1" and python_version < "3.13"
Expand Down
12 changes: 6 additions & 6 deletions requirements.slim.txt
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
asn1crypto==1.5.1 ; python_full_version >= "3.8.1" and python_version < "3.13"
attrs==23.2.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
base58==2.1.1 ; python_full_version >= "3.8.1" and python_version < "3.13"
cached-property==1.5.2 ; python_full_version >= "3.8.1" and python_version < "3.13"
cattrs==23.2.3 ; python_full_version >= "3.8.1" and python_version < "3.13"
certifi==2024.6.2 ; python_full_version >= "3.8.1" and python_version < "3.13"
certifi==2024.7.4 ; python_full_version >= "3.8.1" and python_version < "3.13"
cffi==1.16.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
charset-normalizer==3.3.2 ; python_full_version >= "3.8.1" and python_version < "3.13"
click==8.1.7 ; python_full_version >= "3.8.1" and python_version < "3.13"
coincurve==20.0.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
colorama==0.4.6 ; python_full_version >= "3.8.1" and python_version < "3.13" and platform_system == "Windows"
cryptography==42.0.8 ; python_full_version >= "3.8.1" and python_version < "3.13"
cytoolz==0.12.3 ; python_full_version >= "3.8.1" and python_version < "3.13" and implementation_name == "cpython"
deprecation==2.1.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
docker==7.1.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
eth-hash==0.7.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
eth-typing==4.3.1 ; python_full_version >= "3.8.1" and python_version < "3.13"
eth-typing==4.4.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
eth-utils==4.1.1 ; python_full_version >= "3.8.1" and python_version < "3.13"
exceptiongroup==1.2.1 ; python_full_version >= "3.8.1" and python_version < "3.11"
fastecdsa==2.3.2 ; python_full_version >= "3.8.1" and python_version < "3.13"
idna==3.7 ; python_full_version >= "3.8.1" and python_version < "3.13"
importlib-resources==6.4.0 ; python_full_version >= "3.8.1" and python_version < "3.9"
jsonschema-specifications==2023.12.1 ; python_full_version >= "3.8.1" and python_version < "3.13"
jsonschema==4.22.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
jsonschema==4.23.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
mnemonic==0.21 ; python_full_version >= "3.8.1" and python_version < "3.13"
netstruct==1.1.2 ; python_full_version >= "3.8.1" and python_version < "3.13"
packaging==24.1 ; python_full_version >= "3.8.1" and python_version < "3.13"
Expand All @@ -32,9 +34,7 @@ python-dateutil==2.9.0.post0 ; python_full_version >= "3.8.1" and python_version
pywin32==306 ; python_full_version >= "3.8.1" and python_version < "3.13" and sys_platform == "win32"
referencing==0.35.1 ; python_full_version >= "3.8.1" and python_version < "3.13"
requests==2.32.3 ; python_full_version >= "3.8.1" and python_version < "3.13"
rpds-py==0.18.1 ; python_full_version >= "3.8.1" and python_version < "3.13"
secp256k1==0.14.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
setuptools==70.1.1 ; python_full_version >= "3.8.1" and python_version < "3.13"
rpds-py==0.19.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
simple-bson==0.0.3 ; python_full_version >= "3.8.1" and python_version < "3.13"
simplejson==3.19.2 ; python_full_version >= "3.8.1" and python_version < "3.13"
six==1.16.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
Expand Down
16 changes: 8 additions & 8 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ appnope==0.1.4 ; python_full_version >= "3.8.1" and python_version < "3.13" and
argon2-cffi-bindings==21.2.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
argon2-cffi==23.1.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
arrow==1.3.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
asn1crypto==1.5.1 ; python_full_version >= "3.8.1" and python_version < "3.13"
asttokens==2.4.1 ; python_full_version >= "3.8.1" and python_version < "3.13"
attrs==23.2.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
backcall==0.2.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
Expand All @@ -11,10 +12,11 @@ beautifulsoup4==4.12.3 ; python_full_version >= "3.8.1" and python_version < "3.
bleach==6.1.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
cached-property==1.5.2 ; python_full_version >= "3.8.1" and python_version < "3.13"
cattrs==23.2.3 ; python_full_version >= "3.8.1" and python_version < "3.13"
certifi==2024.6.2 ; python_full_version >= "3.8.1" and python_version < "3.13"
certifi==2024.7.4 ; python_full_version >= "3.8.1" and python_version < "3.13"
cffi==1.16.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
charset-normalizer==3.3.2 ; python_full_version >= "3.8.1" and python_version < "3.13"
click==8.1.7 ; python_full_version >= "3.8.1" and python_version < "3.13"
coincurve==20.0.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
colorama==0.4.6 ; python_full_version >= "3.8.1" and python_version < "3.13" and (platform_system == "Windows" or sys_platform == "win32")
comm==0.2.2 ; python_full_version >= "3.8.1" and python_version < "3.13"
cryptography==42.0.8 ; python_full_version >= "3.8.1" and python_version < "3.13"
Expand All @@ -26,7 +28,7 @@ deprecation==2.1.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
docker==7.1.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
entrypoints==0.4 ; python_full_version >= "3.8.1" and python_version < "3.13"
eth-hash==0.7.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
eth-typing==4.3.1 ; python_full_version >= "3.8.1" and python_version < "3.13"
eth-typing==4.4.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
eth-utils==4.1.1 ; python_full_version >= "3.8.1" and python_version < "3.13"
exceptiongroup==1.2.1 ; python_full_version >= "3.8.1" and python_version < "3.11"
executing==2.0.1 ; python_full_version >= "3.8.1" and python_version < "3.13"
Expand All @@ -36,16 +38,16 @@ fqdn==1.5.1 ; python_full_version >= "3.8.1" and python_version < "3.13"
idna==3.7 ; python_full_version >= "3.8.1" and python_version < "3.13"
importlib-metadata==8.0.0 ; python_full_version >= "3.8.1" and python_version < "3.10"
importlib-resources==6.4.0 ; python_full_version >= "3.8.1" and python_version < "3.9"
ipykernel==6.29.4 ; python_full_version >= "3.8.1" and python_version < "3.13"
ipykernel==6.29.5 ; python_full_version >= "3.8.1" and python_version < "3.13"
ipython-genutils==0.2.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
ipython==8.12.3 ; python_full_version >= "3.8.1" and python_version < "3.13"
isoduration==20.11.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
jedi==0.19.1 ; python_full_version >= "3.8.1" and python_version < "3.13"
jinja2==3.1.4 ; python_full_version >= "3.8.1" and python_version < "3.13"
jsonpointer==3.0.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
jsonschema-specifications==2023.12.1 ; python_full_version >= "3.8.1" and python_version < "3.13"
jsonschema==4.22.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
jsonschema[format-nongpl]==4.22.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
jsonschema==4.23.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
jsonschema[format-nongpl]==4.23.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
jupyter-client==7.4.9 ; python_full_version >= "3.8.1" and python_version < "3.13"
jupyter-core==5.7.2 ; python_full_version >= "3.8.1" and python_version < "3.13"
jupyter-events==0.10.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
Expand Down Expand Up @@ -92,10 +94,8 @@ referencing==0.35.1 ; python_full_version >= "3.8.1" and python_version < "3.13"
requests==2.32.3 ; python_full_version >= "3.8.1" and python_version < "3.13"
rfc3339-validator==0.1.4 ; python_full_version >= "3.8.1" and python_version < "3.13"
rfc3986-validator==0.1.1 ; python_full_version >= "3.8.1" and python_version < "3.13"
rpds-py==0.18.1 ; python_full_version >= "3.8.1" and python_version < "3.13"
secp256k1==0.14.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
rpds-py==0.19.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
send2trash==1.8.3 ; python_full_version >= "3.8.1" and python_version < "3.13"
setuptools==70.1.1 ; python_full_version >= "3.8.1" and python_version < "3.13"
simple-bson==0.0.3 ; python_full_version >= "3.8.1" and python_version < "3.13"
simplejson==3.19.2 ; python_full_version >= "3.8.1" and python_version < "3.13"
six==1.16.0 ; python_full_version >= "3.8.1" and python_version < "3.13"
Expand Down
13 changes: 8 additions & 5 deletions src/pytezos/crypto/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ def __call__(self, *args, **kwargs):
import fastecdsa.encoding.sec1 # type: ignore
import fastecdsa.keys # type: ignore
import pysodium # type: ignore
from coincurve import ecdsa # type: ignore
from fastecdsa.encoding.util import bytes_to_int # type: ignore
except ImportError as e:
coincurve = CryptoExtraFallback()
coincurve = CryptoExtraFallback() # type: ignore
ecdsa = CryptoExtraFallback() # type: ignore
pysodium = CryptoExtraFallback()
fastecdsa = CryptoExtraFallback()
bytes_to_int = CryptoExtraFallback()
Expand Down Expand Up @@ -152,7 +154,7 @@ def from_secret_exponent(
# Secp256k1
elif curve == b'sp':
sk = coincurve.PrivateKey(secret_exponent)
public_point = sk.public_key.format(compressed=True)
public_point = sk.public_key.format()
# P256
elif curve == b'p2':
pk = fastecdsa.keys.get_public_key(bytes_to_int(secret_exponent), curve=fastecdsa.curve.P256)
Expand Down Expand Up @@ -445,8 +447,9 @@ def sign(self, message: Union[str, bytes], generic: bool = False):
# Secp256k1
elif self.curve == b"sp":
pk = coincurve.PrivateKey(self.secret_exponent)
signature = pk.sign(encoded_message, hasher=lambda x: blake2b_32(x).digest())

signature = ecdsa.serialize_compact(
ecdsa.der_to_cdata(pk.sign(encoded_message, hasher=lambda x: blake2b_32(x).digest()))
)
# P256
elif self.curve == b"p2":
r, s = fastecdsa.ecdsa.sign(msg=encoded_message, d=bytes_to_int(self.secret_exponent), hashfunc=blake2b_32)
Expand Down Expand Up @@ -492,7 +495,7 @@ def verify(self, signature: Union[str, bytes], message: Union[str, bytes]) -> bo
elif self.curve == b"sp":
pk = coincurve.PublicKey(self.public_point)
if not pk.verify(
signature=decoded_signature,
signature=ecdsa.cdata_to_der(ecdsa.deserialize_compact(decoded_signature)),
message=encoded_message,
hasher=lambda x: blake2b_32(x).digest(),
):
Expand Down

0 comments on commit 060883b

Please sign in to comment.