Skip to content

Commit

Permalink
upgrade typing
Browse files Browse the repository at this point in the history
move constants
  • Loading branch information
ChihChengLiang committed Mar 5, 2019
1 parent e95a50e commit b76f5d8
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 22 deletions.
8 changes: 5 additions & 3 deletions py_ecc/bls_api/api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from typing import (
Sequence,
)
from eth_typing import (
BLSPubkey,
BLSSignature,
Hash32,
)
from eth_utils import (
ValidationError,
)
Expand All @@ -16,11 +21,8 @@
pairing,
)
from .typing import (
BLSPubkey,
BLSSignature,
G1Uncompressed,
G2Uncompressed,
Hash32,
)
from .utils import (
G1_to_pubkey,
Expand Down
10 changes: 10 additions & 0 deletions py_ecc/bls_api/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
from py_ecc.optimized_bls12_381 import (
FQ2,
field_modulus as q,
)

G2_cofactor = 305502333931268344200999753193121504214466019254188142667664032982267604182971884026507427359259977847832272839041616661285803823378372096355777062779109 # noqa: E501
FQ2_order = q ** 2 - 1
eighth_roots_of_unity = tuple(
FQ2([1, 1]) ** ((FQ2_order * k) // 8)
for k in range(8)
)

POW_2_381 = 2**381
POW_2_382 = 2**382
Expand Down
2 changes: 1 addition & 1 deletion py_ecc/bls_api/hash.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .typing import Hash32
from eth_typing import Hash32
from eth_hash.auto import keccak
from typing import Union

Expand Down
6 changes: 0 additions & 6 deletions py_ecc/bls_api/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@
FQ2,
)


Hash32 = NewType("Hash32", bytes)
BLSPubkey = NewType('BLSPubkey', bytes) # bytes48
BLSSignature = NewType('BLSSignature', bytes) # bytes96


G1Uncompressed = NewType('G1Uncompressed', Tuple[FQ, FQ, FQ])
G1Compressed = NewType('G1Compressed', int)

Expand Down
19 changes: 8 additions & 11 deletions py_ecc/bls_api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
Tuple,
Union,
)

from eth_typing import (
BLSPubkey,
BLSSignature,
Hash32,
)
from eth_utils import (
big_endian_to_int,
)
Expand All @@ -26,27 +30,20 @@
hash_eth2,
)
from .typing import (
BLSPubkey,
BLSSignature,
G1Compressed,
G1Uncompressed,
G2Compressed,
G2Uncompressed,
Hash32,
)
from .constants import (
G2_cofactor,
FQ2_order,
eighth_roots_of_unity,
POW_2_381,
POW_2_382,
POW_2_383,
)

G2_cofactor = 305502333931268344200999753193121504214466019254188142667664032982267604182971884026507427359259977847832272839041616661285803823378372096355777062779109 # noqa: E501
FQ2_order = q ** 2 - 1
eighth_roots_of_unity = [
FQ2([1, 1]) ** ((FQ2_order * k) // 8)
for k in range(8)
]


#
# Helpers
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
package_data={'py_ecc': ['py.typed']},
install_requires=[
"eth-hash[pycryptodome]",
"eth-typing>=2.0.0,<3.0.0",
"eth-typing>=2.1.0,<3.0.0",
"eth-utils>=1.3.0,<2",
"mypy-extensions>=0.4.1",
],
Expand Down

0 comments on commit b76f5d8

Please sign in to comment.