coinex-api 0.0.89__py3-none-any.whl → 0.0.110__py3-none-any.whl
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 coinex-api might be problematic. Click here for more details.
- coinex/ccxt/__init__.py +1 -1
- coinex/ccxt/async_support/__init__.py +1 -1
- coinex/ccxt/async_support/base/exchange.py +139 -10
- coinex/ccxt/async_support/base/throttler.py +1 -1
- coinex/ccxt/async_support/base/ws/cache.py +1 -0
- coinex/ccxt/async_support/base/ws/client.py +26 -4
- coinex/ccxt/async_support/coinex.py +2 -2
- coinex/ccxt/base/exchange.py +587 -91
- coinex/ccxt/base/types.py +11 -2
- coinex/ccxt/coinex.py +2 -2
- coinex/ccxt/pro/__init__.py +1 -1
- coinex/ccxt/pro/coinex.py +10 -7
- coinex/ccxt/static_dependencies/bip/__init__.py +6 -0
- coinex/ccxt/static_dependencies/bip/addr/P2PKH_addr.py +205 -0
- coinex/ccxt/static_dependencies/bip/addr/__init__.py +5 -0
- coinex/ccxt/static_dependencies/bip/addr/addr_dec_utils.py +125 -0
- coinex/ccxt/static_dependencies/bip/addr/addr_key_validator.py +162 -0
- coinex/ccxt/static_dependencies/bip/addr/iaddr_decoder.py +48 -0
- coinex/ccxt/static_dependencies/bip/addr/iaddr_encoder.py +50 -0
- coinex/ccxt/static_dependencies/bip/base58/__init__.py +3 -0
- coinex/ccxt/static_dependencies/bip/base58/base58.py +207 -0
- coinex/ccxt/static_dependencies/bip/base58/base58_ex.py +25 -0
- coinex/ccxt/static_dependencies/bip/base58/base58_xmr.py +155 -0
- coinex/ccxt/static_dependencies/bip/bech32/__init__.py +4 -0
- coinex/ccxt/static_dependencies/bip/bech32/bch_bech32.py +220 -0
- coinex/ccxt/static_dependencies/bip/bech32/bech32.py +235 -0
- coinex/ccxt/static_dependencies/bip/bech32/bech32_base.py +246 -0
- coinex/ccxt/static_dependencies/bip/bech32/bech32_ex.py +25 -0
- coinex/ccxt/static_dependencies/bip/bech32/segwit_bech32.py +173 -0
- coinex/ccxt/static_dependencies/bip/bip32/__init__.py +14 -0
- coinex/ccxt/static_dependencies/bip/bip32/base/__init__.py +3 -0
- coinex/ccxt/static_dependencies/bip/bip32/base/bip32_base.py +581 -0
- coinex/ccxt/static_dependencies/bip/bip32/base/ibip32_key_derivator.py +83 -0
- coinex/ccxt/static_dependencies/bip/bip32/base/ibip32_mst_key_generator.py +47 -0
- coinex/ccxt/static_dependencies/bip/bip32/bip32_const.py +35 -0
- coinex/ccxt/static_dependencies/bip/bip32/bip32_ex.py +29 -0
- coinex/ccxt/static_dependencies/bip/bip32/bip32_key_data.py +500 -0
- coinex/ccxt/static_dependencies/bip/bip32/bip32_key_net_ver.py +83 -0
- coinex/ccxt/static_dependencies/bip/bip32/bip32_key_ser.py +294 -0
- coinex/ccxt/static_dependencies/bip/bip32/bip32_keys.py +457 -0
- coinex/ccxt/static_dependencies/bip/bip32/bip32_path.py +247 -0
- coinex/ccxt/static_dependencies/bip/bip32/bip32_utils.py +72 -0
- coinex/ccxt/static_dependencies/bip/bip32/kholaw/__init__.py +4 -0
- coinex/ccxt/static_dependencies/bip/bip32/kholaw/bip32_kholaw_ed25519.py +82 -0
- coinex/ccxt/static_dependencies/bip/bip32/kholaw/bip32_kholaw_ed25519_key_derivator.py +118 -0
- coinex/ccxt/static_dependencies/bip/bip32/kholaw/bip32_kholaw_key_derivator_base.py +204 -0
- coinex/ccxt/static_dependencies/bip/bip32/kholaw/bip32_kholaw_mst_key_generator.py +119 -0
- coinex/ccxt/static_dependencies/bip/bip32/slip10/__init__.py +1 -0
- coinex/ccxt/static_dependencies/bip/bip32/slip10/bip32_slip10_key_derivator.py +200 -0
- coinex/ccxt/static_dependencies/bip/bip32/slip10/bip32_slip10_mst_key_generator.py +168 -0
- coinex/ccxt/static_dependencies/bip/bip32/slip10/bip32_slip10_secp256k1.py +82 -0
- coinex/ccxt/static_dependencies/bip/bip44/__init__.py +1 -0
- coinex/ccxt/static_dependencies/bip/bip44/bip44.py +265 -0
- coinex/ccxt/static_dependencies/bip/bip44_base/__init__.py +3 -0
- coinex/ccxt/static_dependencies/bip/bip44_base/bip44_base.py +624 -0
- coinex/ccxt/static_dependencies/bip/bip44_base/bip44_base_ex.py +25 -0
- coinex/ccxt/static_dependencies/bip/bip44_base/bip44_keys.py +225 -0
- coinex/ccxt/static_dependencies/bip/coin_conf/__init__.py +2 -0
- coinex/ccxt/static_dependencies/bip/coin_conf/coin_conf.py +68 -0
- coinex/ccxt/static_dependencies/bip/coin_conf/coins_conf.py +890 -0
- coinex/ccxt/static_dependencies/bip/conf/__init__.py +0 -0
- coinex/ccxt/static_dependencies/bip/conf/bip44/__init__.py +3 -0
- coinex/ccxt/static_dependencies/bip/conf/bip44/bip44_coins.py +126 -0
- coinex/ccxt/static_dependencies/bip/conf/bip44/bip44_conf.py +1360 -0
- coinex/ccxt/static_dependencies/bip/conf/bip44/bip44_conf_getter.py +153 -0
- coinex/ccxt/static_dependencies/bip/conf/bip49/__init__.py +3 -0
- coinex/ccxt/static_dependencies/bip/conf/bip49/bip49_coins.py +53 -0
- coinex/ccxt/static_dependencies/bip/conf/bip49/bip49_conf.py +366 -0
- coinex/ccxt/static_dependencies/bip/conf/bip49/bip49_conf_getter.py +80 -0
- coinex/ccxt/static_dependencies/bip/conf/bip84/__init__.py +3 -0
- coinex/ccxt/static_dependencies/bip/conf/bip84/bip84_coins.py +39 -0
- coinex/ccxt/static_dependencies/bip/conf/bip84/bip84_conf.py +113 -0
- coinex/ccxt/static_dependencies/bip/conf/bip84/bip84_conf_getter.py +66 -0
- coinex/ccxt/static_dependencies/bip/conf/bip86/__init__.py +3 -0
- coinex/ccxt/static_dependencies/bip/conf/bip86/bip86_coins.py +37 -0
- coinex/ccxt/static_dependencies/bip/conf/bip86/bip86_conf.py +83 -0
- coinex/ccxt/static_dependencies/bip/conf/bip86/bip86_conf_getter.py +64 -0
- coinex/ccxt/static_dependencies/bip/conf/common/__init__.py +8 -0
- coinex/ccxt/static_dependencies/bip/conf/common/atom_addr.py +104 -0
- coinex/ccxt/static_dependencies/bip/conf/common/bip_bitcoin_cash_conf.py +106 -0
- coinex/ccxt/static_dependencies/bip/conf/common/bip_coin_conf.py +217 -0
- coinex/ccxt/static_dependencies/bip/conf/common/bip_coins.py +28 -0
- coinex/ccxt/static_dependencies/bip/conf/common/bip_conf_const.py +30 -0
- coinex/ccxt/static_dependencies/bip/conf/common/bip_litecoin_conf.py +121 -0
- coinex/ccxt/static_dependencies/bip/ecc/__init__.py +42 -0
- coinex/ccxt/static_dependencies/bip/ecc/common/__init__.py +0 -0
- coinex/ccxt/static_dependencies/bip/ecc/common/dummy_point.py +219 -0
- coinex/ccxt/static_dependencies/bip/ecc/common/ikeys.py +263 -0
- coinex/ccxt/static_dependencies/bip/ecc/common/ipoint.py +190 -0
- coinex/ccxt/static_dependencies/bip/ecc/conf.py +28 -0
- coinex/ccxt/static_dependencies/bip/ecc/curve/__init__.py +0 -0
- coinex/ccxt/static_dependencies/bip/ecc/curve/elliptic_curve.py +121 -0
- coinex/ccxt/static_dependencies/bip/ecc/curve/elliptic_curve_getter.py +74 -0
- coinex/ccxt/static_dependencies/bip/ecc/curve/elliptic_curve_types.py +37 -0
- coinex/ccxt/static_dependencies/bip/ecc/ecdsa/__init__.py +0 -0
- coinex/ccxt/static_dependencies/bip/ecc/ecdsa/ecdsa_keys.py +36 -0
- coinex/ccxt/static_dependencies/bip/ecc/secp256k1/__init__.py +0 -0
- coinex/ccxt/static_dependencies/bip/ecc/secp256k1/secp256k1.py +36 -0
- coinex/ccxt/static_dependencies/bip/ecc/secp256k1/secp256k1_const.py +59 -0
- coinex/ccxt/static_dependencies/bip/ecc/secp256k1/secp256k1_keys_ecdsa.py +248 -0
- coinex/ccxt/static_dependencies/bip/ecc/secp256k1/secp256k1_point_ecdsa.py +234 -0
- coinex/ccxt/static_dependencies/bip/slip/__init__.py +0 -0
- coinex/ccxt/static_dependencies/bip/slip/slip173/__init__.py +1 -0
- coinex/ccxt/static_dependencies/bip/slip/slip173/slip173.py +60 -0
- coinex/ccxt/static_dependencies/bip/slip/slip32/__init__.py +4 -0
- coinex/ccxt/static_dependencies/bip/slip/slip32/slip32.py +322 -0
- coinex/ccxt/static_dependencies/bip/slip/slip32/slip32_key_net_ver.py +62 -0
- coinex/ccxt/static_dependencies/bip/slip/slip44/__init__.py +1 -0
- coinex/ccxt/static_dependencies/bip/slip/slip44/slip44.py +81 -0
- coinex/ccxt/static_dependencies/bip/utils/__init__.py +0 -0
- coinex/ccxt/static_dependencies/bip/utils/conf/__init__.py +1 -0
- coinex/ccxt/static_dependencies/bip/utils/conf/coin_names.py +59 -0
- coinex/ccxt/static_dependencies/bip/utils/crypto/__init__.py +10 -0
- coinex/ccxt/static_dependencies/bip/utils/crypto/aes_ecb.py +152 -0
- coinex/ccxt/static_dependencies/bip/utils/crypto/blake2.py +191 -0
- coinex/ccxt/static_dependencies/bip/utils/crypto/chacha20_poly1305.py +101 -0
- coinex/ccxt/static_dependencies/bip/utils/crypto/hash160.py +57 -0
- coinex/ccxt/static_dependencies/bip/utils/crypto/hmac.py +118 -0
- coinex/ccxt/static_dependencies/bip/utils/crypto/pbkdf2.py +66 -0
- coinex/ccxt/static_dependencies/bip/utils/crypto/ripemd.py +58 -0
- coinex/ccxt/static_dependencies/bip/utils/crypto/scrypt.py +66 -0
- coinex/ccxt/static_dependencies/bip/utils/crypto/sha2.py +182 -0
- coinex/ccxt/static_dependencies/bip/utils/crypto/sha3.py +99 -0
- coinex/ccxt/static_dependencies/bip/utils/misc/__init__.py +7 -0
- coinex/ccxt/static_dependencies/bip/utils/misc/algo.py +108 -0
- coinex/ccxt/static_dependencies/bip/utils/misc/base32.py +151 -0
- coinex/ccxt/static_dependencies/bip/utils/misc/bit.py +115 -0
- coinex/ccxt/static_dependencies/bip/utils/misc/bytes.py +200 -0
- coinex/ccxt/static_dependencies/bip/utils/misc/data_bytes.py +181 -0
- coinex/ccxt/static_dependencies/bip/utils/misc/integer.py +97 -0
- coinex/ccxt/static_dependencies/bip/utils/misc/string.py +54 -0
- coinex/ccxt/static_dependencies/bip/utils/typing/__init__.py +1 -0
- coinex/ccxt/static_dependencies/bip/utils/typing/literal.py +27 -0
- coinex/ccxt/static_dependencies/bip/wif/__init__.py +1 -0
- coinex/ccxt/static_dependencies/bip/wif/wif.py +144 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/amino/amino_pb2.py +31 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/cosmos/base/v1beta1/coin_pb2.py +47 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/cosmos/crypto/multisig/keys_pb2.py +33 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/cosmos/crypto/multisig/v1beta1/multisig_pb2.py +33 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/cosmos/crypto/secp256k1/keys_pb2.py +34 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/cosmos/msg/v1/msg_pb2.py +27 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/cosmos/tx/signing/v1beta1/signing_pb2.py +38 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/cosmos/tx/v1beta1/tx_pb2.py +75 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/cosmos_proto/cosmos_pb2.py +36 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/accountplus/accountplus_pb2.py +31 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/accountplus/genesis_pb2.py +40 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/accountplus/models_pb2.py +26 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/accountplus/params_pb2.py +29 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/accountplus/query_pb2.py +57 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/accountplus/tx_pb2.py +51 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/block_rate_limit_config_pb2.py +37 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/clob_pair_pb2.py +41 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/equity_tier_limit_config_pb2.py +35 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/finalize_block_pb2.py +27 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/liquidations_config_pb2.py +39 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/liquidations_pb2.py +38 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/matches_pb2.py +55 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/mev_pb2.py +49 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/operation_pb2.py +32 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/order_pb2.py +86 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/order_removals_pb2.py +32 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/process_proposer_matches_events_pb2.py +42 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/query_pb2.py +124 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/streaming_pb2.py +29 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/tx_pb2.py +117 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/sending/genesis_pb2.py +26 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/sending/query_pb2.py +26 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/sending/transfer_pb2.py +61 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/sending/tx_pb2.py +37 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/subaccounts/asset_position_pb2.py +29 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/subaccounts/genesis_pb2.py +30 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/subaccounts/perpetual_position_pb2.py +33 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/subaccounts/query_pb2.py +63 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/subaccounts/streaming_pb2.py +31 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/subaccounts/subaccount_pb2.py +33 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/gogoproto/gogo_pb2.py +102 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/registry.py +38 -0
- coinex/ccxt/static_dependencies/ecdsa/ellipticcurve.py +842 -0
- coinex/ccxt/static_dependencies/ecdsa/keys.py +15 -4
- coinex/ccxt/static_dependencies/mnemonic/__init__.py +4 -0
- coinex/ccxt/static_dependencies/mnemonic/mnemonic.py +282 -0
- coinex/ccxt/static_dependencies/mnemonic/py.typed +1 -0
- coinex/ccxt/static_dependencies/mnemonic/wordlist/chinese_simplified.txt +2048 -0
- coinex/ccxt/static_dependencies/mnemonic/wordlist/chinese_traditional.txt +2048 -0
- coinex/ccxt/static_dependencies/mnemonic/wordlist/czech.txt +2048 -0
- coinex/ccxt/static_dependencies/mnemonic/wordlist/english.txt +2048 -0
- coinex/ccxt/static_dependencies/mnemonic/wordlist/french.txt +2048 -0
- coinex/ccxt/static_dependencies/mnemonic/wordlist/italian.txt +2048 -0
- coinex/ccxt/static_dependencies/mnemonic/wordlist/japanese.txt +2048 -0
- coinex/ccxt/static_dependencies/mnemonic/wordlist/korean.txt +2048 -0
- coinex/ccxt/static_dependencies/mnemonic/wordlist/portuguese.txt +2048 -0
- coinex/ccxt/static_dependencies/mnemonic/wordlist/russian.txt +2048 -0
- coinex/ccxt/static_dependencies/mnemonic/wordlist/spanish.txt +2048 -0
- coinex/ccxt/static_dependencies/mnemonic/wordlist/turkish.txt +2048 -0
- {coinex_api-0.0.89.dist-info → coinex_api-0.0.110.dist-info}/METADATA +3 -3
- {coinex_api-0.0.89.dist-info → coinex_api-0.0.110.dist-info}/RECORD +197 -17
- {coinex_api-0.0.89.dist-info → coinex_api-0.0.110.dist-info}/WHEEL +1 -1
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
# Copyright (c) 2021 Emanuele Bellocchia
|
|
2
|
+
#
|
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
# furnished to do so, subject to the following conditions:
|
|
9
|
+
#
|
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
|
11
|
+
# all copies or substantial portions of the Software.
|
|
12
|
+
#
|
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
# THE SOFTWARE.
|
|
20
|
+
|
|
21
|
+
"""Module with interfaces for public/private keys classes."""
|
|
22
|
+
|
|
23
|
+
# Imports
|
|
24
|
+
from __future__ import annotations
|
|
25
|
+
|
|
26
|
+
from abc import ABC, abstractmethod
|
|
27
|
+
from typing import Any
|
|
28
|
+
|
|
29
|
+
from .ipoint import IPoint
|
|
30
|
+
from ..curve.elliptic_curve_types import EllipticCurveTypes
|
|
31
|
+
from ...utils.misc import DataBytes
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class IPublicKey(ABC):
|
|
35
|
+
"""
|
|
36
|
+
Interface for a generic elliptic curve public key.
|
|
37
|
+
Verify method is missing because not needed.
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
@classmethod
|
|
41
|
+
@abstractmethod
|
|
42
|
+
def FromBytes(cls,
|
|
43
|
+
key_bytes: bytes) -> IPublicKey:
|
|
44
|
+
"""
|
|
45
|
+
Construct class from key bytes.
|
|
46
|
+
|
|
47
|
+
Args:
|
|
48
|
+
key_bytes (bytes): Key bytes
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
IPublicKey: IPublicKey object
|
|
52
|
+
|
|
53
|
+
Raises:
|
|
54
|
+
ValueError: If key bytes are not valid
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
@classmethod
|
|
58
|
+
@abstractmethod
|
|
59
|
+
def FromPoint(cls,
|
|
60
|
+
key_point: IPoint) -> IPublicKey:
|
|
61
|
+
"""
|
|
62
|
+
Construct class from key point.
|
|
63
|
+
|
|
64
|
+
Args:
|
|
65
|
+
key_point (IPoint object): Key point
|
|
66
|
+
|
|
67
|
+
Returns:
|
|
68
|
+
IPublicKey: IPublicKey object
|
|
69
|
+
|
|
70
|
+
Raises:
|
|
71
|
+
ValueError: If key point is not valid
|
|
72
|
+
"""
|
|
73
|
+
|
|
74
|
+
@staticmethod
|
|
75
|
+
@abstractmethod
|
|
76
|
+
def CurveType() -> EllipticCurveTypes:
|
|
77
|
+
"""
|
|
78
|
+
Get the elliptic curve type.
|
|
79
|
+
|
|
80
|
+
Returns:
|
|
81
|
+
EllipticCurveTypes: Elliptic curve type
|
|
82
|
+
"""
|
|
83
|
+
|
|
84
|
+
@classmethod
|
|
85
|
+
def IsValidBytes(cls,
|
|
86
|
+
key_bytes: bytes) -> bool:
|
|
87
|
+
"""
|
|
88
|
+
Return if the specified bytes represents a valid public key.
|
|
89
|
+
|
|
90
|
+
Args:
|
|
91
|
+
key_bytes (bytes): Key bytes
|
|
92
|
+
|
|
93
|
+
Returns:
|
|
94
|
+
bool: True if valid, false otherwise
|
|
95
|
+
"""
|
|
96
|
+
try:
|
|
97
|
+
cls.FromBytes(key_bytes)
|
|
98
|
+
return True
|
|
99
|
+
except ValueError:
|
|
100
|
+
return False
|
|
101
|
+
|
|
102
|
+
@classmethod
|
|
103
|
+
def IsValidPoint(cls,
|
|
104
|
+
key_point: IPoint) -> bool:
|
|
105
|
+
"""
|
|
106
|
+
Return if the specified point represents a valid public key.
|
|
107
|
+
|
|
108
|
+
Args:
|
|
109
|
+
key_point (IPoint object): Key point
|
|
110
|
+
|
|
111
|
+
Returns:
|
|
112
|
+
bool: True if valid, false otherwise
|
|
113
|
+
"""
|
|
114
|
+
try:
|
|
115
|
+
cls.FromPoint(key_point)
|
|
116
|
+
return True
|
|
117
|
+
except ValueError:
|
|
118
|
+
return False
|
|
119
|
+
|
|
120
|
+
@staticmethod
|
|
121
|
+
@abstractmethod
|
|
122
|
+
def CompressedLength() -> int:
|
|
123
|
+
"""
|
|
124
|
+
Get the compressed key length.
|
|
125
|
+
|
|
126
|
+
Returns:
|
|
127
|
+
int: Compressed key length
|
|
128
|
+
"""
|
|
129
|
+
|
|
130
|
+
@staticmethod
|
|
131
|
+
@abstractmethod
|
|
132
|
+
def UncompressedLength() -> int:
|
|
133
|
+
"""
|
|
134
|
+
Get the uncompressed key length.
|
|
135
|
+
|
|
136
|
+
Returns:
|
|
137
|
+
int: Uncompressed key length
|
|
138
|
+
"""
|
|
139
|
+
|
|
140
|
+
@abstractmethod
|
|
141
|
+
def UnderlyingObject(self) -> Any:
|
|
142
|
+
"""
|
|
143
|
+
Get the underlying object.
|
|
144
|
+
|
|
145
|
+
Returns:
|
|
146
|
+
Any: Underlying object
|
|
147
|
+
"""
|
|
148
|
+
|
|
149
|
+
@abstractmethod
|
|
150
|
+
def RawCompressed(self) -> DataBytes:
|
|
151
|
+
"""
|
|
152
|
+
Return raw compressed public key.
|
|
153
|
+
|
|
154
|
+
Returns:
|
|
155
|
+
DataBytes object: DataBytes object
|
|
156
|
+
"""
|
|
157
|
+
|
|
158
|
+
@abstractmethod
|
|
159
|
+
def RawUncompressed(self) -> DataBytes:
|
|
160
|
+
"""
|
|
161
|
+
Return raw uncompressed public key.
|
|
162
|
+
|
|
163
|
+
Returns:
|
|
164
|
+
DataBytes object: DataBytes object
|
|
165
|
+
"""
|
|
166
|
+
|
|
167
|
+
@abstractmethod
|
|
168
|
+
def Point(self) -> IPoint:
|
|
169
|
+
"""
|
|
170
|
+
Return the public key point.
|
|
171
|
+
|
|
172
|
+
Returns:
|
|
173
|
+
IPoint object: IPoint object
|
|
174
|
+
"""
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
class IPrivateKey(ABC):
|
|
178
|
+
"""
|
|
179
|
+
Interface for a generic elliptic curve private key.
|
|
180
|
+
Sign method is missing because not needed.
|
|
181
|
+
"""
|
|
182
|
+
|
|
183
|
+
@classmethod
|
|
184
|
+
@abstractmethod
|
|
185
|
+
def FromBytes(cls,
|
|
186
|
+
key_bytes: bytes) -> IPrivateKey:
|
|
187
|
+
"""
|
|
188
|
+
Construct class from key bytes.
|
|
189
|
+
|
|
190
|
+
Args:
|
|
191
|
+
key_bytes (bytes): Key bytes
|
|
192
|
+
|
|
193
|
+
Returns:
|
|
194
|
+
IPrivateKey: IPrivateKey object
|
|
195
|
+
|
|
196
|
+
Raises:
|
|
197
|
+
ValueError: If key bytes are not valid
|
|
198
|
+
"""
|
|
199
|
+
|
|
200
|
+
@staticmethod
|
|
201
|
+
@abstractmethod
|
|
202
|
+
def CurveType() -> EllipticCurveTypes:
|
|
203
|
+
"""
|
|
204
|
+
Get the elliptic curve type.
|
|
205
|
+
|
|
206
|
+
Returns:
|
|
207
|
+
EllipticCurveTypes: Elliptic curve type
|
|
208
|
+
"""
|
|
209
|
+
|
|
210
|
+
@classmethod
|
|
211
|
+
def IsValidBytes(cls,
|
|
212
|
+
key_bytes: bytes) -> bool:
|
|
213
|
+
"""
|
|
214
|
+
Return if the specified bytes represent a valid private key.
|
|
215
|
+
|
|
216
|
+
Args:
|
|
217
|
+
key_bytes (bytes): key bytes
|
|
218
|
+
|
|
219
|
+
Returns:
|
|
220
|
+
bool: True if valid, false otherwise
|
|
221
|
+
"""
|
|
222
|
+
try:
|
|
223
|
+
cls.FromBytes(key_bytes)
|
|
224
|
+
return True
|
|
225
|
+
except ValueError:
|
|
226
|
+
return False
|
|
227
|
+
|
|
228
|
+
@staticmethod
|
|
229
|
+
@abstractmethod
|
|
230
|
+
def Length() -> int:
|
|
231
|
+
"""
|
|
232
|
+
Get the key length.
|
|
233
|
+
|
|
234
|
+
Returns:
|
|
235
|
+
int: Key length
|
|
236
|
+
"""
|
|
237
|
+
|
|
238
|
+
@abstractmethod
|
|
239
|
+
def UnderlyingObject(self) -> Any:
|
|
240
|
+
"""
|
|
241
|
+
Get the underlying object.
|
|
242
|
+
|
|
243
|
+
Returns:
|
|
244
|
+
Any: Underlying object
|
|
245
|
+
"""
|
|
246
|
+
|
|
247
|
+
@abstractmethod
|
|
248
|
+
def Raw(self) -> DataBytes:
|
|
249
|
+
"""
|
|
250
|
+
Return raw private key.
|
|
251
|
+
|
|
252
|
+
Returns:
|
|
253
|
+
DataBytes object: DataBytes object
|
|
254
|
+
"""
|
|
255
|
+
|
|
256
|
+
@abstractmethod
|
|
257
|
+
def PublicKey(self) -> IPublicKey:
|
|
258
|
+
"""
|
|
259
|
+
Get the public key correspondent to the private one.
|
|
260
|
+
|
|
261
|
+
Returns:
|
|
262
|
+
IPublicKey object: IPublicKey object
|
|
263
|
+
"""
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
# Copyright (c) 2021 Emanuele Bellocchia
|
|
2
|
+
#
|
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
# furnished to do so, subject to the following conditions:
|
|
9
|
+
#
|
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
|
11
|
+
# all copies or substantial portions of the Software.
|
|
12
|
+
#
|
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
# THE SOFTWARE.
|
|
20
|
+
|
|
21
|
+
"""Module with interfaces for point classes."""
|
|
22
|
+
|
|
23
|
+
# Imports
|
|
24
|
+
from __future__ import annotations
|
|
25
|
+
|
|
26
|
+
from abc import ABC, abstractmethod
|
|
27
|
+
from typing import Any
|
|
28
|
+
|
|
29
|
+
from ..curve.elliptic_curve_types import EllipticCurveTypes
|
|
30
|
+
from ...utils.misc import DataBytes
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class IPoint(ABC):
|
|
34
|
+
"""Interface for a generic elliptic curve point."""
|
|
35
|
+
|
|
36
|
+
@classmethod
|
|
37
|
+
@abstractmethod
|
|
38
|
+
def FromBytes(cls,
|
|
39
|
+
point_bytes: bytes) -> IPoint:
|
|
40
|
+
"""
|
|
41
|
+
Construct class from point bytes.
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
point_bytes (bytes): Point bytes
|
|
45
|
+
|
|
46
|
+
Returns:
|
|
47
|
+
IPoint: IPoint object
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
@classmethod
|
|
51
|
+
@abstractmethod
|
|
52
|
+
def FromCoordinates(cls,
|
|
53
|
+
x: int,
|
|
54
|
+
y: int) -> IPoint:
|
|
55
|
+
"""
|
|
56
|
+
Construct class from point coordinates.
|
|
57
|
+
|
|
58
|
+
Args:
|
|
59
|
+
x (int): X coordinate of the point
|
|
60
|
+
y (int): Y coordinate of the point
|
|
61
|
+
|
|
62
|
+
Returns:
|
|
63
|
+
IPoint: IPoint object
|
|
64
|
+
"""
|
|
65
|
+
|
|
66
|
+
@staticmethod
|
|
67
|
+
@abstractmethod
|
|
68
|
+
def CurveType() -> EllipticCurveTypes:
|
|
69
|
+
"""
|
|
70
|
+
Get the elliptic curve type.
|
|
71
|
+
|
|
72
|
+
Returns:
|
|
73
|
+
EllipticCurveTypes: Elliptic curve type
|
|
74
|
+
"""
|
|
75
|
+
|
|
76
|
+
@staticmethod
|
|
77
|
+
@abstractmethod
|
|
78
|
+
def CoordinateLength() -> int:
|
|
79
|
+
"""
|
|
80
|
+
Get the coordinate length.
|
|
81
|
+
|
|
82
|
+
Returns:
|
|
83
|
+
int: Coordinate key length
|
|
84
|
+
"""
|
|
85
|
+
|
|
86
|
+
@abstractmethod
|
|
87
|
+
def UnderlyingObject(self) -> Any:
|
|
88
|
+
"""
|
|
89
|
+
Get the underlying object.
|
|
90
|
+
|
|
91
|
+
Returns:
|
|
92
|
+
Any: Underlying object
|
|
93
|
+
"""
|
|
94
|
+
|
|
95
|
+
@abstractmethod
|
|
96
|
+
def X(self) -> int:
|
|
97
|
+
"""
|
|
98
|
+
Return X coordinate of the point.
|
|
99
|
+
|
|
100
|
+
Returns:
|
|
101
|
+
int: X coordinate of the point
|
|
102
|
+
"""
|
|
103
|
+
|
|
104
|
+
@abstractmethod
|
|
105
|
+
def Y(self) -> int:
|
|
106
|
+
"""
|
|
107
|
+
Return Y coordinate of the point.
|
|
108
|
+
|
|
109
|
+
Returns:
|
|
110
|
+
int: Y coordinate of the point
|
|
111
|
+
"""
|
|
112
|
+
|
|
113
|
+
@abstractmethod
|
|
114
|
+
def Raw(self) -> DataBytes:
|
|
115
|
+
"""
|
|
116
|
+
Return the point raw bytes.
|
|
117
|
+
|
|
118
|
+
Returns:
|
|
119
|
+
DataBytes object: DataBytes object
|
|
120
|
+
"""
|
|
121
|
+
|
|
122
|
+
@abstractmethod
|
|
123
|
+
def RawEncoded(self) -> DataBytes:
|
|
124
|
+
"""
|
|
125
|
+
Return the encoded point raw bytes.
|
|
126
|
+
|
|
127
|
+
Returns:
|
|
128
|
+
DataBytes object: DataBytes object
|
|
129
|
+
"""
|
|
130
|
+
|
|
131
|
+
@abstractmethod
|
|
132
|
+
def RawDecoded(self) -> DataBytes:
|
|
133
|
+
"""
|
|
134
|
+
Return the decoded point raw bytes.
|
|
135
|
+
|
|
136
|
+
Returns:
|
|
137
|
+
DataBytes object: DataBytes object
|
|
138
|
+
"""
|
|
139
|
+
|
|
140
|
+
@abstractmethod
|
|
141
|
+
def __add__(self,
|
|
142
|
+
point: IPoint) -> IPoint:
|
|
143
|
+
"""
|
|
144
|
+
Add point to another point.
|
|
145
|
+
|
|
146
|
+
Args:
|
|
147
|
+
point (IPoint object): IPoint object
|
|
148
|
+
|
|
149
|
+
Returns:
|
|
150
|
+
IPoint object: IPoint object
|
|
151
|
+
"""
|
|
152
|
+
|
|
153
|
+
@abstractmethod
|
|
154
|
+
def __radd__(self,
|
|
155
|
+
point: IPoint) -> IPoint:
|
|
156
|
+
"""
|
|
157
|
+
Add point to another point.
|
|
158
|
+
|
|
159
|
+
Args:
|
|
160
|
+
point (IPoint object): IPoint object
|
|
161
|
+
|
|
162
|
+
Returns:
|
|
163
|
+
IPoint object: IPoint object
|
|
164
|
+
"""
|
|
165
|
+
|
|
166
|
+
@abstractmethod
|
|
167
|
+
def __mul__(self,
|
|
168
|
+
scalar: int) -> IPoint:
|
|
169
|
+
"""
|
|
170
|
+
Multiply point by a scalar.
|
|
171
|
+
|
|
172
|
+
Args:
|
|
173
|
+
scalar (int): scalar
|
|
174
|
+
|
|
175
|
+
Returns:
|
|
176
|
+
IPoint object: IPoint object
|
|
177
|
+
"""
|
|
178
|
+
|
|
179
|
+
@abstractmethod
|
|
180
|
+
def __rmul__(self,
|
|
181
|
+
scalar: int) -> IPoint:
|
|
182
|
+
"""
|
|
183
|
+
Multiply point by a scalar.
|
|
184
|
+
|
|
185
|
+
Args:
|
|
186
|
+
scalar (int): scalar
|
|
187
|
+
|
|
188
|
+
Returns:
|
|
189
|
+
IPoint object: IPoint object
|
|
190
|
+
"""
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Copyright (c) 2021 Emanuele Bellocchia
|
|
2
|
+
#
|
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
# furnished to do so, subject to the following conditions:
|
|
9
|
+
#
|
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
|
11
|
+
# all copies or substantial portions of the Software.
|
|
12
|
+
#
|
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
# THE SOFTWARE.
|
|
20
|
+
|
|
21
|
+
"""Module for ECC configuration."""
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class EccConf:
|
|
25
|
+
"""ECC configuration class."""
|
|
26
|
+
|
|
27
|
+
# True for using coincurve for secp256k1, false for using ecdsa
|
|
28
|
+
USE_COINCURVE: bool = False
|
|
File without changes
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# Copyright (c) 2021 Emanuele Bellocchia
|
|
2
|
+
#
|
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
# furnished to do so, subject to the following conditions:
|
|
9
|
+
#
|
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
|
11
|
+
# all copies or substantial portions of the Software.
|
|
12
|
+
#
|
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
# THE SOFTWARE.
|
|
20
|
+
|
|
21
|
+
"""Module with helper class for elliptic curves."""
|
|
22
|
+
|
|
23
|
+
# Imports
|
|
24
|
+
from typing import Type
|
|
25
|
+
|
|
26
|
+
from ..common.ikeys import IPrivateKey, IPublicKey
|
|
27
|
+
from ..common.ipoint import IPoint
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class EllipticCurve:
|
|
31
|
+
"""
|
|
32
|
+
Class for a generic elliptic curve.
|
|
33
|
+
This is not meant to be complete but just the minimum required to abstract the bip module from
|
|
34
|
+
the specific ECC library.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
m_name: str
|
|
38
|
+
m_order: int
|
|
39
|
+
m_generator: IPoint
|
|
40
|
+
m_point_cls: Type[IPoint]
|
|
41
|
+
m_pub_key_cls: Type[IPublicKey]
|
|
42
|
+
m_priv_key_cls: Type[IPrivateKey]
|
|
43
|
+
|
|
44
|
+
def __init__(self, # pylint: disable=too-many-arguments
|
|
45
|
+
name: str,
|
|
46
|
+
order: int,
|
|
47
|
+
generator: IPoint,
|
|
48
|
+
point_cls: Type[IPoint],
|
|
49
|
+
pub_key_cls: Type[IPublicKey],
|
|
50
|
+
priv_key_cls: Type[IPrivateKey]):
|
|
51
|
+
"""
|
|
52
|
+
Construct class.
|
|
53
|
+
|
|
54
|
+
Args:
|
|
55
|
+
name (str) : Curve name
|
|
56
|
+
order (int) : Curve order
|
|
57
|
+
generator (IPoint object) : Curve generator point
|
|
58
|
+
point_cls (IPoint class) : Point class
|
|
59
|
+
pub_key_cls (IPublicKey class) : Public key class
|
|
60
|
+
priv_key_cls (IPrivateKey class): Private key class
|
|
61
|
+
"""
|
|
62
|
+
self.m_name = name
|
|
63
|
+
self.m_order = order
|
|
64
|
+
self.m_generator = generator
|
|
65
|
+
self.m_point_cls = point_cls
|
|
66
|
+
self.m_pub_key_cls = pub_key_cls
|
|
67
|
+
self.m_priv_key_cls = priv_key_cls
|
|
68
|
+
|
|
69
|
+
def Name(self) -> str:
|
|
70
|
+
"""
|
|
71
|
+
Return the curve name.
|
|
72
|
+
|
|
73
|
+
Returns:
|
|
74
|
+
str: Curve name
|
|
75
|
+
"""
|
|
76
|
+
return self.m_name
|
|
77
|
+
|
|
78
|
+
def Order(self) -> int:
|
|
79
|
+
"""
|
|
80
|
+
Return the curve order.
|
|
81
|
+
|
|
82
|
+
Returns:
|
|
83
|
+
int: Curve order
|
|
84
|
+
"""
|
|
85
|
+
return self.m_order
|
|
86
|
+
|
|
87
|
+
def Generator(self) -> IPoint:
|
|
88
|
+
"""
|
|
89
|
+
Get the curve generator point.
|
|
90
|
+
|
|
91
|
+
Returns:
|
|
92
|
+
IPoint object: IPoint object
|
|
93
|
+
"""
|
|
94
|
+
return self.m_generator
|
|
95
|
+
|
|
96
|
+
def PointClass(self) -> Type[IPoint]:
|
|
97
|
+
"""
|
|
98
|
+
Return the point class.
|
|
99
|
+
|
|
100
|
+
Returns:
|
|
101
|
+
IPoint class: Point class
|
|
102
|
+
"""
|
|
103
|
+
return self.m_point_cls
|
|
104
|
+
|
|
105
|
+
def PublicKeyClass(self) -> Type[IPublicKey]:
|
|
106
|
+
"""
|
|
107
|
+
Return the public key class.
|
|
108
|
+
|
|
109
|
+
Returns:
|
|
110
|
+
IPublicKey class: Public key class
|
|
111
|
+
"""
|
|
112
|
+
return self.m_pub_key_cls
|
|
113
|
+
|
|
114
|
+
def PrivateKeyClass(self) -> Type[IPrivateKey]:
|
|
115
|
+
"""
|
|
116
|
+
Return the private key class.
|
|
117
|
+
|
|
118
|
+
Returns:
|
|
119
|
+
IPrivateKey class: Private key class
|
|
120
|
+
"""
|
|
121
|
+
return self.m_priv_key_cls
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Copyright (c) 2021 Emanuele Bellocchia
|
|
2
|
+
#
|
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
# furnished to do so, subject to the following conditions:
|
|
9
|
+
#
|
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
|
11
|
+
# all copies or substantial portions of the Software.
|
|
12
|
+
#
|
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
# THE SOFTWARE.
|
|
20
|
+
|
|
21
|
+
"""Module for getting elliptic curves classes."""
|
|
22
|
+
|
|
23
|
+
# Imports
|
|
24
|
+
from typing import Dict
|
|
25
|
+
|
|
26
|
+
from .elliptic_curve import EllipticCurve
|
|
27
|
+
from .elliptic_curve_types import EllipticCurveTypes
|
|
28
|
+
# from ..ed25519.ed25519 import Ed25519
|
|
29
|
+
# from ..ed25519_blake2b.ed25519_blake2b import Ed25519Blake2b
|
|
30
|
+
# from ..ed25519_kholaw.ed25519_kholaw import Ed25519Kholaw
|
|
31
|
+
# from ..ed25519_monero.ed25519_monero import Ed25519Monero
|
|
32
|
+
# from ..nist256p1.nist256p1 import Nist256p1
|
|
33
|
+
from ..secp256k1.secp256k1 import Secp256k1
|
|
34
|
+
# from ..sr25519.sr25519 import Sr25519
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class EllipticCurveGetterConst:
|
|
38
|
+
"""Class container for elliptic curve getter constants."""
|
|
39
|
+
|
|
40
|
+
# Elliptic curve type to instance
|
|
41
|
+
TYPE_TO_INSTANCE: Dict[EllipticCurveTypes, EllipticCurve] = {
|
|
42
|
+
# EllipticCurveTypes.ED25519: Ed25519,
|
|
43
|
+
# EllipticCurveTypes.ED25519_BLAKE2B: Ed25519Blake2b,
|
|
44
|
+
# EllipticCurveTypes.ED25519_KHOLAW: Ed25519Kholaw,
|
|
45
|
+
# EllipticCurveTypes.ED25519_MONERO: Ed25519Monero,
|
|
46
|
+
# EllipticCurveTypes.NIST256P1: Nist256p1,
|
|
47
|
+
EllipticCurveTypes.SECP256K1: Secp256k1,
|
|
48
|
+
# EllipticCurveTypes.SR25519: Sr25519,
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class EllipticCurveGetter:
|
|
53
|
+
"""
|
|
54
|
+
Elliptic curve getter class.
|
|
55
|
+
It allows to get the elliptic curve class from its type.
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
@staticmethod
|
|
59
|
+
def FromType(curve_type: EllipticCurveTypes) -> EllipticCurve:
|
|
60
|
+
"""
|
|
61
|
+
Get the elliptic curve class from its type.
|
|
62
|
+
|
|
63
|
+
Args:
|
|
64
|
+
curve_type (EllipticCurveTypes): Curve type
|
|
65
|
+
|
|
66
|
+
Returns:
|
|
67
|
+
EllipticCurve object: EllipticCurve object
|
|
68
|
+
|
|
69
|
+
Raises:
|
|
70
|
+
TypeError: If curve type is not a EllipticCurveTypes enum
|
|
71
|
+
"""
|
|
72
|
+
if not isinstance(curve_type, EllipticCurveTypes):
|
|
73
|
+
raise TypeError("Curve type is not an enumerative of EllipticCurveTypes")
|
|
74
|
+
return EllipticCurveGetterConst.TYPE_TO_INSTANCE[curve_type]
|