cchecksum 0.0.6__tar.gz → 0.0.8__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of cchecksum might be problematic. Click here for more details.

Files changed (43) hide show
  1. {cchecksum-0.0.6 → cchecksum-0.0.8}/.github/workflows/deploy-docs.yaml +6 -0
  2. {cchecksum-0.0.6 → cchecksum-0.0.8}/.github/workflows/release.yaml +1 -1
  3. {cchecksum-0.0.6/cchecksum.egg-info → cchecksum-0.0.8}/PKG-INFO +3 -2
  4. {cchecksum-0.0.6 → cchecksum-0.0.8}/cchecksum/checksum.py +30 -35
  5. cchecksum-0.0.8/cchecksum/checksum.pyi +31 -0
  6. {cchecksum-0.0.6 → cchecksum-0.0.8/cchecksum.egg-info}/PKG-INFO +3 -2
  7. {cchecksum-0.0.6 → cchecksum-0.0.8}/cchecksum.egg-info/SOURCES.txt +2 -1
  8. {cchecksum-0.0.6 → cchecksum-0.0.8}/.github/workflows/black.yaml +0 -0
  9. {cchecksum-0.0.6 → cchecksum-0.0.8}/.github/workflows/pytest.yaml +0 -0
  10. {cchecksum-0.0.6 → cchecksum-0.0.8}/.gitignore +0 -0
  11. {cchecksum-0.0.6 → cchecksum-0.0.8}/LICENSE +0 -0
  12. {cchecksum-0.0.6 → cchecksum-0.0.8}/Makefile +0 -0
  13. {cchecksum-0.0.6 → cchecksum-0.0.8}/README.md +0 -0
  14. {cchecksum-0.0.6 → cchecksum-0.0.8}/cchecksum/__init__.py +0 -0
  15. {cchecksum-0.0.6 → cchecksum-0.0.8}/cchecksum/_checksum.c +0 -0
  16. /cchecksum-0.0.6/cchecksum/_cchecksum.pyi → /cchecksum-0.0.8/cchecksum/_checksum.pyi +0 -0
  17. {cchecksum-0.0.6 → cchecksum-0.0.8}/cchecksum/_checksum.pyx +0 -0
  18. {cchecksum-0.0.6 → cchecksum-0.0.8}/cchecksum/py.typed +0 -0
  19. {cchecksum-0.0.6 → cchecksum-0.0.8}/cchecksum.egg-info/dependency_links.txt +0 -0
  20. {cchecksum-0.0.6 → cchecksum-0.0.8}/cchecksum.egg-info/not-zip-safe +0 -0
  21. {cchecksum-0.0.6 → cchecksum-0.0.8}/cchecksum.egg-info/requires.txt +0 -0
  22. {cchecksum-0.0.6 → cchecksum-0.0.8}/cchecksum.egg-info/top_level.txt +0 -0
  23. {cchecksum-0.0.6 → cchecksum-0.0.8}/docs/Makefile +0 -0
  24. {cchecksum-0.0.6 → cchecksum-0.0.8}/docs/_build/html/_static/alabaster.css +0 -0
  25. {cchecksum-0.0.6 → cchecksum-0.0.8}/docs/_build/html/_static/basic.css +0 -0
  26. {cchecksum-0.0.6 → cchecksum-0.0.8}/docs/_build/html/_static/custom.css +0 -0
  27. {cchecksum-0.0.6 → cchecksum-0.0.8}/docs/_build/html/_static/doctools.js +0 -0
  28. {cchecksum-0.0.6 → cchecksum-0.0.8}/docs/_build/html/_static/documentation_options.js +0 -0
  29. {cchecksum-0.0.6 → cchecksum-0.0.8}/docs/_build/html/_static/file.png +0 -0
  30. {cchecksum-0.0.6 → cchecksum-0.0.8}/docs/_build/html/_static/language_data.js +0 -0
  31. {cchecksum-0.0.6 → cchecksum-0.0.8}/docs/_build/html/_static/minus.png +0 -0
  32. {cchecksum-0.0.6 → cchecksum-0.0.8}/docs/_build/html/_static/plus.png +0 -0
  33. {cchecksum-0.0.6 → cchecksum-0.0.8}/docs/_build/html/_static/pygments.css +0 -0
  34. {cchecksum-0.0.6 → cchecksum-0.0.8}/docs/_build/html/_static/searchtools.js +0 -0
  35. {cchecksum-0.0.6 → cchecksum-0.0.8}/docs/_build/html/_static/sphinx_highlight.js +0 -0
  36. {cchecksum-0.0.6 → cchecksum-0.0.8}/docs/conf.py +0 -0
  37. {cchecksum-0.0.6 → cchecksum-0.0.8}/docs/index.rst +0 -0
  38. {cchecksum-0.0.6 → cchecksum-0.0.8}/docs/make.bat +0 -0
  39. {cchecksum-0.0.6 → cchecksum-0.0.8}/pyproject.toml +0 -0
  40. {cchecksum-0.0.6 → cchecksum-0.0.8}/requirements.txt +0 -0
  41. {cchecksum-0.0.6 → cchecksum-0.0.8}/setup.cfg +0 -0
  42. {cchecksum-0.0.6 → cchecksum-0.0.8}/setup.py +0 -0
  43. {cchecksum-0.0.6 → cchecksum-0.0.8}/test_checksum.py +0 -0
@@ -5,15 +5,21 @@ on:
5
5
  branches:
6
6
  - master
7
7
 
8
+
8
9
  # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
9
10
  permissions:
10
11
  contents: write
11
12
  id-token: write
12
13
  pages: write
14
+
13
15
 
14
16
  jobs:
15
17
  build-and-deploy:
16
18
  runs-on: ubuntu-latest
19
+
20
+ environment:
21
+ name: github-pages
22
+
17
23
  steps:
18
24
  - name: Check out code
19
25
  uses: actions/checkout@v2
@@ -8,7 +8,7 @@ on:
8
8
 
9
9
  jobs:
10
10
  deploy:
11
- runs-on: ubuntu-20.04
11
+ runs-on: ubuntu-latest
12
12
 
13
13
  steps:
14
14
  - uses: actions/checkout@v2
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: cchecksum
3
- Version: 0.0.6
3
+ Version: 0.0.8
4
4
  Summary: A ~2x faster drop-in replacement for eth_utils.to_checksum_address. Raises the exact same Exceptions. Implemented in C.
5
5
  Home-page: https://github.com/BobTheBuidler/cchecksum
6
6
  Author: BobTheBuidler
@@ -15,6 +15,7 @@ Dynamic: author
15
15
  Dynamic: author-email
16
16
  Dynamic: home-page
17
17
  Dynamic: license
18
+ Dynamic: license-file
18
19
  Dynamic: requires-dist
19
20
  Dynamic: requires-python
20
21
  Dynamic: summary
@@ -3,12 +3,24 @@ from typing import Optional, Union
3
3
 
4
4
  from eth_hash.auto import keccak
5
5
  from eth_typing import AnyAddress, ChecksumAddress, HexAddress, HexStr, Primitives
6
- from eth_utils import add_0x_prefix, encode_hex, hexstr_if_str
6
+ from eth_utils import encode_hex, hexstr_if_str
7
7
  from eth_utils.address import _HEX_ADDRESS_REGEXP
8
+ from eth_utils.toolz import compose
8
9
 
9
10
  from cchecksum._checksum import cchecksum
10
11
 
11
12
 
13
+ BytesLike = Union[Primitives, bytearray, memoryview]
14
+
15
+
16
+ # force _hasher_first_run and _preimage_first_run to execute so we can cache the new hasher
17
+ keccak(b"")
18
+
19
+ hash_address = compose(hexlify, bytes, keccak.hasher, str.encode)
20
+
21
+ hex_address_fullmatch = _HEX_ADDRESS_REGEXP.fullmatch
22
+
23
+
12
24
  # this was ripped out of eth_utils and optimized a little bit
13
25
 
14
26
 
@@ -40,8 +52,7 @@ def to_checksum_address(value: Union[AnyAddress, str, bytes]) -> ChecksumAddress
40
52
  - :func:`to_normalized_address` for converting to a normalized address before checksumming.
41
53
  """
42
54
  norm_address_no_0x = to_normalized_address(value)[2:]
43
- address_hash = bytes(keccak(norm_address_no_0x.encode("utf-8")))
44
- address_hash_hex_no_0x = hexlify(address_hash).decode("ascii")
55
+ address_hash_hex_no_0x = hash_address(norm_address_no_0x).decode("ascii")
45
56
  return cchecksum(norm_address_no_0x, address_hash_hex_no_0x)
46
57
 
47
58
 
@@ -75,10 +86,13 @@ def to_normalized_address(value: Union[AnyAddress, str, bytes]) -> HexAddress:
75
86
  """
76
87
  try:
77
88
  hex_address = hexstr_if_str(to_hex, value).lower()
78
- except AttributeError:
79
- raise TypeError(f"Value must be any string, instead got type {type(value)}")
89
+ except AttributeError as e:
90
+ raise TypeError(
91
+ f"Value must be any string, instead got type {type(value)}"
92
+ ) from e.__cause__
80
93
 
81
- if not is_address(hex_address):
94
+ # if `hex_address` is not a valid address
95
+ if hex_address_fullmatch(hex_address) is None:
82
96
  raise ValueError(
83
97
  f"Unknown format {repr(value)}, attempted to normalize to {repr(hex_address)}"
84
98
  )
@@ -86,33 +100,7 @@ def to_normalized_address(value: Union[AnyAddress, str, bytes]) -> HexAddress:
86
100
  return hex_address # type: ignore [return-value]
87
101
 
88
102
 
89
- def is_address(value: str) -> bool:
90
- """
91
- Check if the given string is a valid address in any known format.
92
-
93
- This function uses a regular expression to determine if the input string
94
- matches the expected pattern for a hexadecimal address.
95
-
96
- Args:
97
- value: The string to be checked.
98
-
99
- Returns:
100
- True if the string is a valid address, False otherwise.
101
-
102
- Examples:
103
- >>> is_address("0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb")
104
- True
105
-
106
- >>> is_address("not-an-address")
107
- False
108
-
109
- See Also:
110
- - :func:`eth_utils.is_address` for the standard implementation.
111
- """
112
- return _HEX_ADDRESS_REGEXP.fullmatch(value) is not None
113
-
114
-
115
- BytesLike = Union[Primitives, bytearray, memoryview]
103
+ encode_memoryview = compose(encode_hex, bytes)
116
104
 
117
105
 
118
106
  def to_hex(
@@ -126,14 +114,21 @@ def to_hex(
126
114
  https://github.com/ethereum/wiki/wiki/JSON-RPC#hex-value-encoding
127
115
  """
128
116
  if hexstr is not None:
129
- return add_0x_prefix(hexstr.lower())
117
+ return hexstr if hexstr.startswith(("0x", "0X")) else f"0x{hexstr}"
130
118
 
131
119
  if isinstance(address_bytes, (bytes, bytearray)):
132
120
  return encode_hex(address_bytes)
133
121
 
134
122
  if isinstance(address_bytes, memoryview):
135
- return encode_hex(bytes(address_bytes))
123
+ return encode_memoryview(address_bytes)
136
124
 
137
125
  raise TypeError(
138
126
  f"Unsupported type: '{repr(type(address_bytes))}'. Must be one of: bytes or bytearray."
139
127
  )
128
+
129
+
130
+ del hexlify
131
+ del Optional, Union
132
+ del AnyAddress, ChecksumAddress, HexAddress, HexStr, Primitives
133
+ del _HEX_ADDRESS_REGEXP, compose, keccak
134
+ del BytesLike
@@ -0,0 +1,31 @@
1
+ from typing import Union
2
+
3
+ from eth_typing import AnyAddress, ChecksumAddress
4
+
5
+ def to_checksum_address(value: Union[AnyAddress, str, bytes]) -> ChecksumAddress:
6
+ """
7
+ Convert an address to its EIP-55 checksum format.
8
+
9
+ This function takes an address in any supported format and returns it in the
10
+ checksummed format as defined by EIP-55. It uses a custom Cython implementation
11
+ for the checksum conversion to optimize performance.
12
+
13
+ Args:
14
+ value: The address to be converted. It can be in any format supported by
15
+ :func:`eth_utils.to_normalized_address`.
16
+
17
+ Raises:
18
+ ValueError: If the input address is not in a recognized format.
19
+ TypeError: If the input is not a string, bytes, or any address type.
20
+
21
+ Examples:
22
+ >>> to_checksum_address("0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb")
23
+ '0xb47e3cd837dDF8e4c57F05d70Ab865de6e193BBB'
24
+
25
+ >>> to_checksum_address(b'\xb4~<\xd87\xdd\xf8\xe4\xc5\x7f\x05\xd7\n\xb8e\xden\x19;\xbb')
26
+ '0xb47e3cd837dDF8e4c57F05d70Ab865de6e193BBB'
27
+
28
+ See Also:
29
+ - :func:`eth_utils.to_checksum_address` for the standard implementation.
30
+ - :func:`to_normalized_address` for converting to a normalized address before checksumming.
31
+ """
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: cchecksum
3
- Version: 0.0.6
3
+ Version: 0.0.8
4
4
  Summary: A ~2x faster drop-in replacement for eth_utils.to_checksum_address. Raises the exact same Exceptions. Implemented in C.
5
5
  Home-page: https://github.com/BobTheBuidler/cchecksum
6
6
  Author: BobTheBuidler
@@ -15,6 +15,7 @@ Dynamic: author
15
15
  Dynamic: author-email
16
16
  Dynamic: home-page
17
17
  Dynamic: license
18
+ Dynamic: license-file
18
19
  Dynamic: requires-dist
19
20
  Dynamic: requires-python
20
21
  Dynamic: summary
@@ -11,10 +11,11 @@ test_checksum.py
11
11
  .github/workflows/pytest.yaml
12
12
  .github/workflows/release.yaml
13
13
  cchecksum/__init__.py
14
- cchecksum/_cchecksum.pyi
15
14
  cchecksum/_checksum.c
15
+ cchecksum/_checksum.pyi
16
16
  cchecksum/_checksum.pyx
17
17
  cchecksum/checksum.py
18
+ cchecksum/checksum.pyi
18
19
  cchecksum/py.typed
19
20
  cchecksum.egg-info/PKG-INFO
20
21
  cchecksum.egg-info/SOURCES.txt
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes