|
1 | | -from dydx3.starkex.starkex_resources.cpp_signature import ( |
2 | | - check_cpp_lib_path, cpp_hash, cpp_sign, cpp_verify |
3 | | -) |
4 | | -from dydx3.starkex.starkex_resources.python_signature import ( |
5 | | - py_sign, ECSignature, ECPoint, py_verify, py_pedersen_hash |
6 | | -) |
7 | 1 | from typing import Optional, Union |
8 | 2 |
|
9 | | -def sign(msg_hash: int, priv_key: int, seed: Optional[int] = None) -> ECSignature: |
10 | | - if check_cpp_lib_path(): |
11 | | - return cpp_sign(msg_hash=msg_hash, priv_key=priv_key, seed=seed) |
| 3 | +from dydx3.starkex.starkex_resources.cpp_signature import check_cpp_lib_path |
| 4 | +from dydx3.starkex.starkex_resources.cpp_signature import cpp_hash |
| 5 | +from dydx3.starkex.starkex_resources.cpp_signature import cpp_verify |
| 6 | +from dydx3.starkex.starkex_resources.python_signature import ECPoint |
| 7 | +from dydx3.starkex.starkex_resources.python_signature import ECSignature |
| 8 | +from dydx3.starkex.starkex_resources.python_signature import py_pedersen_hash |
| 9 | +from dydx3.starkex.starkex_resources.python_signature import py_sign |
| 10 | +from dydx3.starkex.starkex_resources.python_signature import py_verify |
12 | 11 |
|
13 | | - return py_sign(msg_hash=msg_hash, priv_key=priv_key, seed=seed) |
14 | 12 |
|
15 | | -def verify(msg_hash: int, r: int, s: int, public_key: Union[int, ECPoint]) -> bool: |
16 | | - if check_cpp_lib_path(): |
17 | | - return cpp_verify(msg_hash=msg_hash, r=r, s=s, stark_key=public_key) |
| 13 | +def sign( |
| 14 | + msg_hash: int, |
| 15 | + priv_key: int, |
| 16 | + seed: Optional[int] = None, |
| 17 | +) -> ECSignature: |
| 18 | + # Note: cpp_sign() is not optimized and is currently slower than py_sign(). |
| 19 | + # So always use py_sign() for now. |
| 20 | + return py_sign(msg_hash=msg_hash, priv_key=priv_key, seed=seed) |
| 21 | + |
| 22 | + |
| 23 | +def verify( |
| 24 | + msg_hash: int, |
| 25 | + r: int, |
| 26 | + s: int, |
| 27 | + public_key: Union[int, ECPoint], |
| 28 | +) -> bool: |
| 29 | + if check_cpp_lib_path(): |
| 30 | + return cpp_verify(msg_hash=msg_hash, r=r, s=s, stark_key=public_key) |
| 31 | + |
| 32 | + return py_verify(msg_hash=msg_hash, r=r, s=s, public_key=public_key) |
18 | 33 |
|
19 | | - return py_verify(msg_hash=msg_hash, r=r, s=s, public_key=public_key) |
20 | 34 |
|
21 | 35 | def get_hash(*elements: int) -> int: |
22 | | - if check_cpp_lib_path(): |
23 | | - return cpp_hash(*elements) |
| 36 | + if check_cpp_lib_path(): |
| 37 | + return cpp_hash(*elements) |
24 | 38 |
|
25 | | - return py_pedersen_hash(*elements) |
| 39 | + return py_pedersen_hash(*elements) |
0 commit comments