Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Python 3.12 and 3.13, venv and Nix #101

Closed
wants to merge 14 commits into from
Closed
2 changes: 1 addition & 1 deletion .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
matrix:
python-version: [
"3.7", "3.8", "3.9", "3.10", "3.11"
"3.8", "3.9", "3.10", "3.11", "3.12", "3.13"
]
steps:
- uses: actions/checkout@master
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ __pycache__/

# py.test stuff
.pytest_cache/
*~
.#*
39 changes: 24 additions & 15 deletions GNUmakefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
SHELL = /bin/bash
PY3 ?= $(shell python3 --version >/dev/null 2>&1 && echo python3 || echo python )
VERSION = $(shell $(PY3) -c 'from hdwallet import __version__; print( __version__.strip("v"))')
PY3_V = $(shell $(PY3) -c "import sys; print('-'.join((next(iter(filter(None,sys.executable.split('/')))),sys.platform,sys.implementation.cache_tag)))" 2>/dev/null )
VERSION = $(shell $(PY3) -c 'exec(open("hdwallet/version.py", "r").read()); print( __version__.strip("v"))')
WHEEL = dist/hdwallet-$(VERSION)-py3-none-any.whl

PY3TEST = $(PY3) -m pytest

GHUB_NAME = python-hdwallet
VENV_DIR = $(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/.. )
VENV_NAME = $(GHUB_NAME)-$(VERSION)-$(PY3_V)
VENV = $(VENV_DIR)/$(VENV_NAME)
VENV_OPTS =

.PHONY: all test build build-check wheel install-dev install clean FORCE

all: build
Expand All @@ -19,28 +26,30 @@ test-%:
unit-%:
$(PY3TEST) -k $*

build: clean wheel
nix-%:
nix-shell --pure --run "make $*"

build-check:
@$(PY3) -m build --version \
|| ( \
echo -e "\n\n!!! Missing Python modules; run:"; \
echo -e "\n\n $(PY3) -m pip install --upgrade pip setuptools wheel build\n"; \
false; \
)
build: clean wheel

wheel: $(WHEEL)

$(WHEEL): build-check FORCE
$(WHEEL): FORCE
$(PY3) -m pip install -r requirements-dev.txt
$(PY3) -m build
@ls -last dist

# Install from wheel, including all optional extra dependencies (except dev)
install-dev: $(WHEEL) FORCE
$(PY3) -m pip install --upgrade $<[tests]

install: $(WHEEL) FORCE
$(PY3) -m pip install --force-reinstall $<[cli,docs]
$(PY3) -m pip install --force-reinstall .[cli,docs]

clean:
@rm -rf build dist *.egg-info $(shell find . -name '__pycache__' )

venv: $(VENV)
@echo; echo "*** Activating $< VirtualEnv for Interactive $(SHELL)"
@bash --init-file $</bin/activate -i

$(VENV):
@echo; echo "*** Building $@ VirtualEnv..."
@rm -rf $@ && $(PY3) -m venv $(VENV_OPTS) $@ \
&& source $@/bin/activate \
&& make install
3 changes: 2 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
include LICENSE
include README.md
include requirements.txt
include requirements*.txt

global-exclude *~
recursive-exclude * __pycache__
recursive-exclude * *.py[co]
62 changes: 62 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{ pkgs ? import ./nixpkgs.nix {} }:

with pkgs;

let
in
{
py313 = stdenv.mkDerivation rec {
name = "python313-with-pytest";

buildInputs = [
git
openssh
python313
python313Packages.pytest
];
};

py312 = stdenv.mkDerivation rec {
name = "python312-with-pytest";

buildInputs = [
git
openssh
python312
python312Packages.pytest
];
};

py311 = stdenv.mkDerivation rec {
name = "python311-with-pytest";

buildInputs = [
git
openssh
python311
python311Packages.pytest
];
};

py310 = stdenv.mkDerivation rec {
name = "python310-with-pytest";

buildInputs = [
git
openssh
python310
python310Packages.pytest
];
};

py39 = stdenv.mkDerivation rec {
name = "python39-with-pytest";

buildInputs = [
git
openssh
python39
python39Packages.pytest
];
};
}
6 changes: 5 additions & 1 deletion hdwallet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
)

# HDWallet Information's
__version__: str = "v2.2.1"
from .version import (
__version__,
__version_info__
)
__license__: str = "MIT"
__author__: str = "Meheret Tesfaye Batu"
__email__: str = "[email protected]"
Expand All @@ -19,6 +22,7 @@

__all__: list = [
"__version__",
"__version_info__",
"__license__",
"__author__",
"__email__",
Expand Down
200 changes: 200 additions & 0 deletions hdwallet/cryptocurrencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -2153,6 +2153,206 @@ class EthereumMainnet(Cryptocurrency):
WIF_SECRET_KEY = 0x80


class BinanceSmartChainMainnet(Cryptocurrency):

NAME = "Binance Smart Chain"
SYMBOL = "BSC"
NETWORK = "mainnet"
SOURCE_CODE = "https://github.com/bnb-chain/bsc"
COIN_TYPE = CoinType({
"INDEX": 9006,
"HARDENED": True
})

SCRIPT_ADDRESS = 0x05
PUBLIC_KEY_ADDRESS = 0x00
SEGWIT_ADDRESS = SegwitAddress({
"HRP": "bc",
"VERSION": 0x00
})

EXTENDED_PRIVATE_KEY = ExtendedPrivateKey({
"P2PKH": 0x0488ade4,
"P2SH": 0x0488ade4,
"P2WPKH": 0x04b2430c,
"P2WPKH_IN_P2SH": 0x049d7878,
"P2WSH": 0x02aa7a99,
"P2WSH_IN_P2SH": 0x0295b005
})
EXTENDED_PUBLIC_KEY = ExtendedPublicKey({
"P2PKH": 0x0488b21e,
"P2SH": 0x0488b21e,
"P2WPKH": 0x04b24746,
"P2WPKH_IN_P2SH": 0x049d7cb2,
"P2WSH": 0x02aa7ed3,
"P2WSH_IN_P2SH": 0x0295b43f
})

MESSAGE_PREFIX = None
DEFAULT_PATH = f"m/44'/{str(COIN_TYPE)}/0'/0/0"
WIF_SECRET_KEY = 0x80


class PolygonMainnet(Cryptocurrency):

NAME = "Polygon"
SYMBOL = "MATIC"
NETWORK = "mainnet"
SOURCE_CODE = "https://github.com/bnb-chain/bsc"
COIN_TYPE = CoinType({
"INDEX": 966,
"HARDENED": True
})

SCRIPT_ADDRESS = 0x05
PUBLIC_KEY_ADDRESS = 0x00
SEGWIT_ADDRESS = SegwitAddress({
"HRP": "bc",
"VERSION": 0x00
})

EXTENDED_PRIVATE_KEY = ExtendedPrivateKey({
"P2PKH": 0x0488ade4,
"P2SH": 0x0488ade4,
"P2WPKH": 0x04b2430c,
"P2WPKH_IN_P2SH": 0x049d7878,
"P2WSH": 0x02aa7a99,
"P2WSH_IN_P2SH": 0x0295b005
})
EXTENDED_PUBLIC_KEY = ExtendedPublicKey({
"P2PKH": 0x0488b21e,
"P2SH": 0x0488b21e,
"P2WPKH": 0x04b24746,
"P2WPKH_IN_P2SH": 0x049d7cb2,
"P2WSH": 0x02aa7ed3,
"P2WSH_IN_P2SH": 0x0295b43f
})

MESSAGE_PREFIX = None
DEFAULT_PATH = f"m/44'/{str(COIN_TYPE)}/0'/0/0"
WIF_SECRET_KEY = 0x80


class ArbitrumMainnet(Cryptocurrency):

NAME = "Arbitrum"
SYMBOL = "ARB1"
NETWORK = "mainnet"
SOURCE_CODE = "https://github.com/bnb-chain/bsc"
COIN_TYPE = CoinType({
"INDEX": 9001,
"HARDENED": True
})

SCRIPT_ADDRESS = 0x05
PUBLIC_KEY_ADDRESS = 0x00
SEGWIT_ADDRESS = SegwitAddress({
"HRP": "bc",
"VERSION": 0x00
})

EXTENDED_PRIVATE_KEY = ExtendedPrivateKey({
"P2PKH": 0x0488ade4,
"P2SH": 0x0488ade4,
"P2WPKH": 0x04b2430c,
"P2WPKH_IN_P2SH": 0x049d7878,
"P2WSH": 0x02aa7a99,
"P2WSH_IN_P2SH": 0x0295b005
})
EXTENDED_PUBLIC_KEY = ExtendedPublicKey({
"P2PKH": 0x0488b21e,
"P2SH": 0x0488b21e,
"P2WPKH": 0x04b24746,
"P2WPKH_IN_P2SH": 0x049d7cb2,
"P2WSH": 0x02aa7ed3,
"P2WSH_IN_P2SH": 0x0295b43f
})

MESSAGE_PREFIX = None
DEFAULT_PATH = f"m/44'/{str(COIN_TYPE)}/0'/0/0"
WIF_SECRET_KEY = 0x80


class zkSyncMainnet(Cryptocurrency):

NAME = "zkSync"
SYMBOL = "ZKS"
NETWORK = "mainnet"
SOURCE_CODE = "https://github.com/bnb-chain/bsc"
COIN_TYPE = CoinType({
"INDEX": 804,
"HARDENED": True
})

SCRIPT_ADDRESS = 0x05
PUBLIC_KEY_ADDRESS = 0x00
SEGWIT_ADDRESS = SegwitAddress({
"HRP": "bc",
"VERSION": 0x00
})

EXTENDED_PRIVATE_KEY = ExtendedPrivateKey({
"P2PKH": 0x0488ade4,
"P2SH": 0x0488ade4,
"P2WPKH": 0x04b2430c,
"P2WPKH_IN_P2SH": 0x049d7878,
"P2WSH": 0x02aa7a99,
"P2WSH_IN_P2SH": 0x0295b005
})
EXTENDED_PUBLIC_KEY = ExtendedPublicKey({
"P2PKH": 0x0488b21e,
"P2SH": 0x0488b21e,
"P2WPKH": 0x04b24746,
"P2WPKH_IN_P2SH": 0x049d7cb2,
"P2WSH": 0x02aa7ed3,
"P2WSH_IN_P2SH": 0x0295b43f
})

MESSAGE_PREFIX = None
DEFAULT_PATH = f"m/44'/{str(COIN_TYPE)}/0'/0/0"
WIF_SECRET_KEY = 0x80


class LineaMainnet(Cryptocurrency):

NAME = "Linea"
SYMBOL = "LINEA"
NETWORK = "mainnet"
SOURCE_CODE = "https://github.com/bnb-chain/bsc"
COIN_TYPE = CoinType({
"INDEX": 59144,
"HARDENED": True
})

SCRIPT_ADDRESS = 0x05
PUBLIC_KEY_ADDRESS = 0x00
SEGWIT_ADDRESS = SegwitAddress({
"HRP": "bc",
"VERSION": 0x00
})

EXTENDED_PRIVATE_KEY = ExtendedPrivateKey({
"P2PKH": 0x0488ade4,
"P2SH": 0x0488ade4,
"P2WPKH": 0x04b2430c,
"P2WPKH_IN_P2SH": 0x049d7878,
"P2WSH": 0x02aa7a99,
"P2WSH_IN_P2SH": 0x0295b005
})
EXTENDED_PUBLIC_KEY = ExtendedPublicKey({
"P2PKH": 0x0488b21e,
"P2SH": 0x0488b21e,
"P2WPKH": 0x04b24746,
"P2WPKH_IN_P2SH": 0x049d7cb2,
"P2WSH": 0x02aa7ed3,
"P2WSH_IN_P2SH": 0x0295b43f
})

MESSAGE_PREFIX = None
DEFAULT_PATH = f"m/44'/{str(COIN_TYPE)}/0'/0/0"
WIF_SECRET_KEY = 0x80


class EuropeCoinMainnet(Cryptocurrency):

NAME = "Europe Coin"
Expand Down
6 changes: 3 additions & 3 deletions hdwallet/derivations.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def from_path(cls, path: str) -> "Derivation":

>>> from hdwallet.derivations import Derivation
>>> derivation = Derivation()
>>> derivation.from_path(path="m/44'/0'/'0/0/0")
>>> derivation.from_path(path="m/44'/0'/0'/0/0")
<hdwallet.derivation.Derivation object at 0x000001E8BFB98D60>
"""

Expand Down Expand Up @@ -123,9 +123,9 @@ def clean_derivation(self) -> "Derivation":

>>> from hdwallet.derivations import Derivation
>>> derivation = Derivation()
>>> derivation.from_path(path="m/44'/0'/'0/0/0")
>>> derivation.from_path(path="m/44'/0'/0'/0/0")
>>> str(derivation)
"m/44'/0'/'0/0/0"
"m/44'/0'/0'/0/0"
>>> derivation.clean_derivation()
<hdwallet.wallet.HDWallet object at 0x000001E8BFB98D60>
>>> str(derivation)
Expand Down
Loading