1{ lib
2, fetchFromGitHub
3, buildPythonPackage
4, pythonAtLeast
5, pythonOlder
6, pytest
7, safe-pysha3
8, pycryptodome
9}:
10
11buildPythonPackage rec {
12 pname = "eth-hash";
13 version = "0.5.2";
14 disabled = pythonOlder "3.5";
15
16 src = fetchFromGitHub {
17 owner = "ethereum";
18 repo = "eth-hash";
19 rev = "v${version}";
20 hash = "sha256-6UN+kvLjjAtkmLgUaovjZC/6n3FZtXCwyXZH7ijQObU=";
21 };
22
23 nativeCheckInputs = [
24 pytest
25 ] ++ passthru.optional-dependencies.pycryptodome
26 # eth-hash can use either safe-pysha3 or pycryptodome;
27 # safe-pysha3 requires Python 3.9+ while pycryptodome does not.
28 # https://github.com/ethereum/eth-hash/issues/46#issuecomment-1314029211
29 ++ lib.optional (pythonAtLeast "3.9") passthru.optional-dependencies.pysha3;
30
31 checkPhase = ''
32 pytest tests/backends/pycryptodome/
33 '' + lib.optionalString (pythonAtLeast "3.9") ''
34 pytest tests/backends/pysha3/
35 '';
36
37 passthru.optional-dependencies = {
38 pycryptodome = [ pycryptodome ];
39 pysha3 = [ safe-pysha3 ];
40 };
41
42 meta = with lib; {
43 description = "The Ethereum hashing function keccak256";
44 homepage = "https://github.com/ethereum/eth-hash";
45 license = licenses.mit;
46 maintainers = with maintainers; [ ];
47 };
48}