diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index eceed53c..1cfa1afa 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -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 diff --git a/.gitignore b/.gitignore index 5d8f3a20..022fb51b 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,5 @@ __pycache__/ # py.test stuff .pytest_cache/ +*~ +.#* diff --git a/GNUmakefile b/GNUmakefile index 73be7d4c..3b423f5e 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -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 @@ -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 $ "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") """ @@ -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() >>> str(derivation) diff --git a/hdwallet/hdwallet.py b/hdwallet/hdwallet.py index a66ac84d..a08fec07 100644 --- a/hdwallet/hdwallet.py +++ b/hdwallet/hdwallet.py @@ -437,7 +437,7 @@ def from_path(self, path: Union[str, Derivation]) -> "HDWallet": >>> from hdwallet.symbols import BTC >>> hdwallet = HDWallet(symbol=BTC) >>> hdwallet.from_xprivate_key(xprivate_key="xprv9s21ZrQH143K3xPGUzpogJeKtRdjHkK6muBJo8v7rEVRzT83xJgNcLpMoJXUf9wJFKfuHR4SGvfgdShh4t9VmjjrE9usBunK3LfNna31LGF") - >>> hdwallet.from_path(path="m/44'/0'/'0/0/0") + >>> hdwallet.from_path(path="m/44'/0'/0'/0/0") """ @@ -483,7 +483,7 @@ def from_index(self, index: int, hardened: bool = False) -> "HDWallet": if hardened: self._path += ("/%d'" % index) - self._derive_key_by_index(index + BIP32KEY_HARDEN) + return self._derive_key_by_index(index + BIP32KEY_HARDEN) else: self._path += ("/%d" % index) return self._derive_key_by_index(index) @@ -598,7 +598,7 @@ def root_xprivate_key(self, encoded: bool = True) -> Optional[str]: >>> from hdwallet.symbols import BTC >>> hdwallet = HDWallet(symbol=BTC) >>> hdwallet.from_entropy(entropy="ee535b143b0d9d1f87546f9df0d06b1a") - >>> hdwallet.from_path(path="m/44'/0'/'0/0/0") + >>> hdwallet.from_path(path="m/44'/0'/0'/0/0") >>> hdwallet.root_xprivate_key() "xprv9s21ZrQH143K3xPGUzpogJeKtRdjHkK6muBJo8v7rEVRzT83xJgNcLpMoJXUf9wJFKfuHR4SGvfgdShh4t9VmjjrE9usBunK3LfNna31LGF" """ @@ -636,7 +636,7 @@ def root_xpublic_key(self, encoded: bool = True) -> Optional[str]: >>> from hdwallet.symbols import BTC >>> hdwallet = HDWallet(symbol=BTC) >>> hdwallet.from_entropy(entropy="ee535b143b0d9d1f87546f9df0d06b1a") - >>> hdwallet.from_path(path="m/44'/0'/'0/0/0") + >>> hdwallet.from_path(path="m/44'/0'/0'/0/0") >>> hdwallet.root_xpublic_key() "xpub661MyMwAqRbcGSTjb2Mp3Sb4STUDhD2x986ubXKjQa2QsFTCVqzdA98qeZjcncHT1AaZcMSjiP1HJ16jH97q72RwyFfiNhmG8zQ6KBB5PaQ" """ @@ -679,7 +679,7 @@ def xprivate_key(self, encoded=True) -> Optional[str]: >>> from hdwallet.symbols import BTC >>> hdwallet = HDWallet(symbol=BTC) >>> hdwallet.from_entropy(entropy="ee535b143b0d9d1f87546f9df0d06b1a") - >>> hdwallet.from_path(path="m/44'/0'/'0/0/0") + >>> hdwallet.from_path(path="m/44'/0'/0'/0/0") >>> hdwallet.xprivate_key() "xprvA3BYGWQ9FmhyaNRRXB2f1LphNPnaY9T6gngw4BaTbkFtscSH4RCuJhgWUSKs9S6ciGioHd4TX4UeyUg53MkfN9Xh38xkS1j2Wb9YKsYpJHQ" """ @@ -717,7 +717,7 @@ def xpublic_key(self, encoded: bool = True) -> Optional[str]: >>> from hdwallet.symbols import BTC >>> hdwallet = HDWallet(symbol=BTC) >>> hdwallet.from_entropy(entropy="ee535b143b0d9d1f87546f9df0d06b1a") - >>> hdwallet.from_path(path="m/44'/0'/'0/0/0") + >>> hdwallet.from_path(path="m/44'/0'/0'/0/0") >>> hdwallet.xpublic_key() "xpub6GAtg1w369GGnrVtdCZfNUmRvRd4wcAx41cXrZz5A5nskQmRbxX9rVzzKiRU4JruirBrfm4KQXNSU7GfqL1tzZWpZYe9Zo4xKGJYohWoQe7" """ @@ -750,9 +750,9 @@ def clean_derivation(self) -> "HDWallet": >>> from hdwallet.symbols import BTC >>> hdwallet = HDWallet(symbol=BTC) >>> hdwallet.from_xprivate_key(xprivate_key="xprv9s21ZrQH143K3xPGUzpogJeKtRdjHkK6muBJo8v7rEVRzT83xJgNcLpMoJXUf9wJFKfuHR4SGvfgdShh4t9VmjjrE9usBunK3LfNna31LGF") - >>> hdwallet.from_path(path="m/44'/0'/'0/0/0") + >>> hdwallet.from_path(path="m/44'/0'/0'/0/0") >>> hdwallet.path() - "m/44'/0'/'0/0/0" + "m/44'/0'/0'/0/0" >>> hdwallet.clean_derivation() >>> hdwallet.path() diff --git a/hdwallet/symbols.py b/hdwallet/symbols.py index e78d3790..5fc4c06d 100644 --- a/hdwallet/symbols.py +++ b/hdwallet/symbols.py @@ -28,6 +28,8 @@ BTDX = "BTDX" # Bit Send BSD = "BSD" +# BNB Smart Chain +BSC = "BSC" # Bitcoin Cash BCH = "BCH" # Bitcoin Gold @@ -160,6 +162,10 @@ LKR = "LKR" # Lynx LYNX = "LYNX" +# Polygon +MATIC = "MATIC" +# Arbitrum +ARB1 = "ARB1" # Mazacoin MZC = "MZC" # Megacoin @@ -292,11 +298,18 @@ ZEC, ZECTEST = "ZEC", "ZECTEST" # Zencash ZEN = "ZEN" +# zkSync +ZKS = "ZKS" +# Linea +LINEA = "LINEA" __all__ = [ "ANON", "AGM", + "LINEA", + "ARB1", + "ZKS", "XAX", "AYA", "AC", @@ -310,6 +323,7 @@ "BTDX", "BSD", "BCH", + "BSC", "BTG", "BTC", "BTCTEST", "XBC", @@ -379,6 +393,7 @@ "MEC", "MNX", "MONA", + "MATIC", "MONK", "XMY", "NIX", diff --git a/hdwallet/version.py b/hdwallet/version.py new file mode 100644 index 00000000..f934d459 --- /dev/null +++ b/hdwallet/version.py @@ -0,0 +1,2 @@ +__version_info__ = ( 2, 3, 0 ) +__version__ = 'v' + '.'.join( map( str, __version_info__ )) diff --git a/nixpkgs.nix b/nixpkgs.nix new file mode 100644 index 00000000..7880ec3d --- /dev/null +++ b/nixpkgs.nix @@ -0,0 +1,4 @@ +import (fetchTarball { + url = "https://github.com/NixOS/nixpkgs/archive/refs/tags/23.11.tar.gz"; + sha256 = "1ndiv385w1qyb3b18vw13991fzb9wg4cl21wglk89grsfsnra41k"; +}) diff --git a/requirements-cli.txt b/requirements-cli.txt new file mode 100644 index 00000000..a6a72213 --- /dev/null +++ b/requirements-cli.txt @@ -0,0 +1,3 @@ +click >=8.1.3,<9 +click-aliases >=1.0.1,<2 +tabulate >=0.9.0,<1 diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 00000000..bc210ece --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,4 @@ +build +packaging +setuptools +wheel diff --git a/requirements-docs.txt b/requirements-docs.txt new file mode 100644 index 00000000..c77b2466 --- /dev/null +++ b/requirements-docs.txt @@ -0,0 +1,3 @@ +sphinx >=5.3.0,<6 +furo ==2022.12.7 +sphinx-click >=4.4.0,<5 diff --git a/requirements-tests.txt b/requirements-tests.txt new file mode 100644 index 00000000..7f50a1f2 --- /dev/null +++ b/requirements-tests.txt @@ -0,0 +1,3 @@ +pytest >=7.2.0,<8 +pytest-cov >=4.0.0,<5 +tox ==3.28.0 diff --git a/requirements.txt b/requirements.txt index 5887f801..ad551687 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -ecdsa>=0.13,<1 -mnemonic>=0.19,<1 -pycryptodome>=3.15,<4 -base58>=2.0.1,<3 +ecdsa >=0.19.0,<1 +mnemonic >=0.21,<1 +pycryptodome >=3.21,<4 +base58 >=2.1.1,<3 diff --git a/setup.py b/setup.py index 728237b7..7990ca8a 100644 --- a/setup.py +++ b/setup.py @@ -11,16 +11,27 @@ } # README.md -with open("README.md", "r", encoding="utf-8") as readme: +with open( "README.md", "r", encoding="utf-8") as readme: long_description: str = readme.read() - -# requirements.txt -with open("requirements.txt", "r") as _requirements: - requirements: list = list(map(str.strip, _requirements.read().split("\n"))) +with open( "requirements.txt" ) as r: + install_requires: list = list( r.readlines() ) +with open( "requirements-tests.txt" ) as rt: + tests_require: list = list( rt.readlines() ) +extras_require: dict = { + option: list( + # Remove whitespace, elide blank lines and comments + ''.join( r.split() ) + for r in open( f"requirements-{option}.txt" ).readlines() + if r.strip() and not r.strip().startswith( '#' ) + ) + for option in ('cli', 'tests', 'docs') +} +with open( "hdwallet/version.py" ) as vpy: + exec( vpy.read() ) setup( name="hdwallet", - version="v2.2.1", + version=__version__, description="Python-based library for the implementation of a hierarchical deterministic wallet " "generator for more than 140+ multiple cryptocurrencies.", long_description=long_description, @@ -38,32 +49,18 @@ }, python_requires=">=3.6,<4", packages=find_packages(), - install_requires=requirements, - extras_require={ - "cli": [ - "click>=8.1.3,<9", - "click-aliases>=1.0.1,<2", - "tabulate>=0.9.0,<1" - ], - "tests": [ - "pytest>=7.2.0,<8", - "pytest-cov>=4.0.0,<5", - "tox==3.28.0" - ], - "docs": [ - "sphinx>=5.3.0,<6", - "furo==2022.12.7", - "sphinx-click>=4.4.0,<5" - ] - }, + install_requires=install_requires, + extras_require=extras_require, + tests_require=tests_require, classifiers=[ "Development Status :: 5 - Production/Stable", "License :: OSI Approved :: ISC License (ISCL)", - "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", "Topic :: Software Development :: Libraries :: Python Modules" ] ) diff --git a/shell.nix b/shell.nix new file mode 100644 index 00000000..aab28b37 --- /dev/null +++ b/shell.nix @@ -0,0 +1,19 @@ +{ pkgs ? import ./nixpkgs.nix {} }: + +let + targets = import ./default.nix { + inherit pkgs; + }; + targeted = builtins.getEnv "TARGET"; + selected = targeted + pkgs.lib.optionalString (targeted == "") "py312"; +in + +with pkgs; + +mkShell { + buildInputs = lib.getAttrFromPath [ selected "buildInputs" ] targets; + + shellHook = '' + echo "Welcome to the Python ${selected} environment!" + ''; +}