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
coinex/ccxt/base/types.py
CHANGED
|
@@ -4,14 +4,14 @@ from typing import Union, List, Optional, Any as PythonAny
|
|
|
4
4
|
from decimal import Decimal
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
if sys.version_info
|
|
7
|
+
if sys.version_info >= (3, 8):
|
|
8
8
|
from typing import TypedDict, Literal, Dict
|
|
9
9
|
else:
|
|
10
10
|
from typing import Dict
|
|
11
11
|
from typing_extensions import Literal
|
|
12
12
|
TypedDict = Dict
|
|
13
13
|
|
|
14
|
-
if sys.version_info
|
|
14
|
+
if sys.version_info >= (3, 11):
|
|
15
15
|
from typing import NotRequired
|
|
16
16
|
else:
|
|
17
17
|
from typing_extensions import NotRequired
|
|
@@ -191,6 +191,8 @@ class Liquidation(TypedDict):
|
|
|
191
191
|
baseValue: Num
|
|
192
192
|
quoteValue: Num
|
|
193
193
|
side: OrderSide
|
|
194
|
+
contracts: Num
|
|
195
|
+
contractSize: Num
|
|
194
196
|
|
|
195
197
|
|
|
196
198
|
class FundingHistory(TypedDict):
|
|
@@ -500,6 +502,13 @@ class FundingRate(TypedDict):
|
|
|
500
502
|
info: Dict[str, Any]
|
|
501
503
|
interval: Str
|
|
502
504
|
|
|
505
|
+
class FundingRateHistory(TypedDict):
|
|
506
|
+
symbol: Str
|
|
507
|
+
timestamp: Int
|
|
508
|
+
fundingRate: Num
|
|
509
|
+
datetime: Str
|
|
510
|
+
info: Dict[str, Any]
|
|
511
|
+
|
|
503
512
|
class OpenInterest(TypedDict):
|
|
504
513
|
symbol: Str
|
|
505
514
|
openInterestAmount: Num
|
coinex/ccxt/coinex.py
CHANGED
|
@@ -1600,7 +1600,7 @@ class coinex(Exchange, ImplicitAPI):
|
|
|
1600
1600
|
self.safe_number(ohlcv, 'value'),
|
|
1601
1601
|
]
|
|
1602
1602
|
|
|
1603
|
-
def fetch_ohlcv(self, symbol: str, timeframe='1m', since: Int = None, limit: Int = None, params={}) -> List[list]:
|
|
1603
|
+
def fetch_ohlcv(self, symbol: str, timeframe: str = '1m', since: Int = None, limit: Int = None, params={}) -> List[list]:
|
|
1604
1604
|
"""
|
|
1605
1605
|
fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
|
|
1606
1606
|
|
|
@@ -2616,7 +2616,7 @@ class coinex(Exchange, ImplicitAPI):
|
|
|
2616
2616
|
results.append(order)
|
|
2617
2617
|
return results
|
|
2618
2618
|
|
|
2619
|
-
def cancel_orders(self, ids, symbol: Str = None, params={}):
|
|
2619
|
+
def cancel_orders(self, ids: List[str], symbol: Str = None, params={}):
|
|
2620
2620
|
"""
|
|
2621
2621
|
cancel multiple orders
|
|
2622
2622
|
|
coinex/ccxt/pro/__init__.py
CHANGED
coinex/ccxt/pro/coinex.py
CHANGED
|
@@ -102,8 +102,10 @@ class coinex(coinexAsync):
|
|
|
102
102
|
})
|
|
103
103
|
|
|
104
104
|
def request_id(self):
|
|
105
|
+
self.lock_id()
|
|
105
106
|
requestId = self.sum(self.safe_integer(self.options, 'requestId', 0), 1)
|
|
106
107
|
self.options['requestId'] = requestId
|
|
108
|
+
self.unlock_id()
|
|
107
109
|
return requestId
|
|
108
110
|
|
|
109
111
|
def handle_ticker(self, client: Client, message):
|
|
@@ -165,7 +167,7 @@ class coinex(coinexAsync):
|
|
|
165
167
|
defaultType = self.safe_string(self.options, 'defaultType')
|
|
166
168
|
data = self.safe_dict(message, 'data', {})
|
|
167
169
|
rawTickers = self.safe_list(data, 'state_list', [])
|
|
168
|
-
newTickers =
|
|
170
|
+
newTickers = {}
|
|
169
171
|
for i in range(0, len(rawTickers)):
|
|
170
172
|
entry = rawTickers[i]
|
|
171
173
|
marketId = self.safe_string(entry, 'market')
|
|
@@ -173,7 +175,7 @@ class coinex(coinexAsync):
|
|
|
173
175
|
market = self.safe_market(marketId, None, None, defaultType)
|
|
174
176
|
parsedTicker = self.parse_ws_ticker(entry, market)
|
|
175
177
|
self.tickers[symbol] = parsedTicker
|
|
176
|
-
newTickers
|
|
178
|
+
newTickers[symbol] = parsedTicker
|
|
177
179
|
messageHashes = self.find_message_hashes(client, 'tickers::')
|
|
178
180
|
for i in range(0, len(messageHashes)):
|
|
179
181
|
messageHash = messageHashes[i]
|
|
@@ -643,6 +645,7 @@ class coinex(coinexAsync):
|
|
|
643
645
|
market = self.market(symbol)
|
|
644
646
|
messageHashes.append('tickers::' + market['symbol'])
|
|
645
647
|
else:
|
|
648
|
+
marketIds = []
|
|
646
649
|
messageHashes.append('tickers')
|
|
647
650
|
type = None
|
|
648
651
|
type, params = self.handle_market_type_and_params('watchTickers', market, params)
|
|
@@ -705,13 +708,13 @@ class coinex(coinexAsync):
|
|
|
705
708
|
type = None
|
|
706
709
|
type, params = self.handle_market_type_and_params(callerMethodName, market, params)
|
|
707
710
|
url = self.urls['api']['ws'][type]
|
|
708
|
-
subscriptionHashes = ['trades']
|
|
711
|
+
# subscriptionHashes = ['trades']
|
|
709
712
|
subscribe: dict = {
|
|
710
713
|
'method': 'deals.subscribe',
|
|
711
714
|
'params': {'market_list': subscribedSymbols},
|
|
712
715
|
'id': self.request_id(),
|
|
713
716
|
}
|
|
714
|
-
trades = await self.watch_multiple(url, messageHashes, self.deep_extend(subscribe, params),
|
|
717
|
+
trades = await self.watch_multiple(url, messageHashes, self.deep_extend(subscribe, params), messageHashes)
|
|
715
718
|
if self.newUpdates:
|
|
716
719
|
return trades
|
|
717
720
|
return self.filter_by_since_limit(trades, since, limit, 'timestamp', True)
|
|
@@ -762,9 +765,9 @@ class coinex(coinexAsync):
|
|
|
762
765
|
'params': {'market_list': marketList},
|
|
763
766
|
'id': self.request_id(),
|
|
764
767
|
}
|
|
765
|
-
subscriptionHashes = self.hash(self.encode(self.json(watchOrderBookSubscriptions)), 'sha256')
|
|
768
|
+
# subscriptionHashes = self.hash(self.encode(self.json(watchOrderBookSubscriptions)), 'sha256')
|
|
766
769
|
url = self.urls['api']['ws'][type]
|
|
767
|
-
orderbooks = await self.watch_multiple(url, messageHashes, self.deep_extend(subscribe, params),
|
|
770
|
+
orderbooks = await self.watch_multiple(url, messageHashes, self.deep_extend(subscribe, params), messageHashes)
|
|
768
771
|
if self.newUpdates:
|
|
769
772
|
return orderbooks
|
|
770
773
|
return orderbooks.limit()
|
|
@@ -1343,7 +1346,7 @@ class coinex(coinexAsync):
|
|
|
1343
1346
|
time = self.milliseconds()
|
|
1344
1347
|
timestamp = str(time)
|
|
1345
1348
|
messageHash = 'authenticated'
|
|
1346
|
-
future = client.
|
|
1349
|
+
future = client.reusableFuture(messageHash)
|
|
1347
1350
|
authenticated = self.safe_value(client.subscriptions, messageHash)
|
|
1348
1351
|
if authenticated is not None:
|
|
1349
1352
|
return await future
|
|
@@ -0,0 +1,205 @@
|
|
|
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 P2PKH address encoding/decoding."""
|
|
22
|
+
|
|
23
|
+
# Imports
|
|
24
|
+
from enum import Enum, auto, unique
|
|
25
|
+
from typing import Any, Union
|
|
26
|
+
|
|
27
|
+
from .addr_dec_utils import AddrDecUtils
|
|
28
|
+
from .addr_key_validator import AddrKeyValidator
|
|
29
|
+
from .iaddr_decoder import IAddrDecoder
|
|
30
|
+
from .iaddr_encoder import IAddrEncoder
|
|
31
|
+
from ..base58 import Base58Alphabets, Base58ChecksumError, Base58Decoder, Base58Encoder
|
|
32
|
+
from ..bech32 import BchBech32Decoder, BchBech32Encoder, Bech32ChecksumError
|
|
33
|
+
from ..ecc import IPublicKey
|
|
34
|
+
from ..utils.crypto import Hash160
|
|
35
|
+
from ..utils.misc import BytesUtils
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@unique
|
|
39
|
+
class P2PKHPubKeyModes(Enum):
|
|
40
|
+
"""Enumerative for P2PKH public key modes."""
|
|
41
|
+
|
|
42
|
+
COMPRESSED = auto()
|
|
43
|
+
UNCOMPRESSED = auto()
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class P2PKHAddrDecoder(IAddrDecoder):
|
|
47
|
+
"""
|
|
48
|
+
P2PKH address decoder class.
|
|
49
|
+
It allows the Pay-to-Public-Key-Hash address decoding.
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
@staticmethod
|
|
53
|
+
def DecodeAddr(addr: str,
|
|
54
|
+
**kwargs: Any) -> bytes:
|
|
55
|
+
"""
|
|
56
|
+
Decode a P2PKH address to bytes.
|
|
57
|
+
|
|
58
|
+
Args:
|
|
59
|
+
addr (str): Address string
|
|
60
|
+
|
|
61
|
+
Other Parameters:
|
|
62
|
+
net_ver (bytes) : Expected net address version
|
|
63
|
+
base58_alph (Base58Alphabets, optional): Base58 alphabet (default: Bitcoin alphabet)
|
|
64
|
+
|
|
65
|
+
Returns:
|
|
66
|
+
bytes: Public key hash bytes
|
|
67
|
+
|
|
68
|
+
Raises:
|
|
69
|
+
ValueError: If the address encoding is not valid
|
|
70
|
+
"""
|
|
71
|
+
net_ver_bytes = kwargs["net_ver"]
|
|
72
|
+
base58_alph = kwargs.get("base58_alph", Base58Alphabets.BITCOIN)
|
|
73
|
+
|
|
74
|
+
try:
|
|
75
|
+
addr_dec_bytes = Base58Decoder.CheckDecode(addr, base58_alph)
|
|
76
|
+
except Base58ChecksumError as ex:
|
|
77
|
+
raise ValueError("Invalid base58 checksum") from ex
|
|
78
|
+
|
|
79
|
+
# Validate length
|
|
80
|
+
AddrDecUtils.ValidateLength(addr_dec_bytes,
|
|
81
|
+
Hash160.DigestSize() + len(net_ver_bytes))
|
|
82
|
+
# Validate and remove prefix
|
|
83
|
+
return AddrDecUtils.ValidateAndRemovePrefix(addr_dec_bytes, net_ver_bytes)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
class P2PKHAddrEncoder(IAddrEncoder):
|
|
87
|
+
"""
|
|
88
|
+
P2PKH address encoder class.
|
|
89
|
+
It allows the Pay-to-Public-Key-Hash address encoding.
|
|
90
|
+
"""
|
|
91
|
+
|
|
92
|
+
@staticmethod
|
|
93
|
+
def EncodeKey(pub_key: Union[bytes, IPublicKey],
|
|
94
|
+
**kwargs: Any) -> str:
|
|
95
|
+
"""
|
|
96
|
+
Encode a public key to P2PKH address.
|
|
97
|
+
|
|
98
|
+
Args:
|
|
99
|
+
pub_key (bytes or IPublicKey): Public key bytes or object
|
|
100
|
+
|
|
101
|
+
Other Parameters:
|
|
102
|
+
net_ver (bytes) : Net address version
|
|
103
|
+
base58_alph (Base58Alphabets, optional) : Base58 alphabet, Bitcoin alphabet by default
|
|
104
|
+
pub_key_mode (P2PKHPubKeyModes, optional): Public key mode, compressed key by default
|
|
105
|
+
|
|
106
|
+
Returns:
|
|
107
|
+
str: Address string
|
|
108
|
+
|
|
109
|
+
Raises:
|
|
110
|
+
ValueError: If the public key is not valid
|
|
111
|
+
TypeError: If the public key is not secp256k1
|
|
112
|
+
"""
|
|
113
|
+
net_ver_bytes = kwargs["net_ver"]
|
|
114
|
+
base58_alph = kwargs.get("base58_alph", Base58Alphabets.BITCOIN)
|
|
115
|
+
pub_key_mode = kwargs.get("pub_key_mode", P2PKHPubKeyModes.COMPRESSED)
|
|
116
|
+
|
|
117
|
+
pub_key_obj = AddrKeyValidator.ValidateAndGetSecp256k1Key(pub_key)
|
|
118
|
+
pub_key_bytes = (pub_key_obj.RawCompressed().ToBytes()
|
|
119
|
+
if pub_key_mode == P2PKHPubKeyModes.COMPRESSED
|
|
120
|
+
else pub_key_obj.RawUncompressed().ToBytes())
|
|
121
|
+
|
|
122
|
+
return Base58Encoder.CheckEncode(net_ver_bytes + Hash160.QuickDigest(pub_key_bytes), base58_alph)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
class BchP2PKHAddrDecoder(IAddrDecoder):
|
|
126
|
+
"""
|
|
127
|
+
Bitcoin Cash P2PKH address decoder class.
|
|
128
|
+
It allows the Bitcoin Cash P2PKH decoding.
|
|
129
|
+
"""
|
|
130
|
+
|
|
131
|
+
@staticmethod
|
|
132
|
+
def DecodeAddr(addr: str,
|
|
133
|
+
**kwargs: Any) -> bytes:
|
|
134
|
+
"""
|
|
135
|
+
Decode a Bitcoin Cash P2PKH address to bytes.
|
|
136
|
+
|
|
137
|
+
Args:
|
|
138
|
+
addr (str): Address string
|
|
139
|
+
|
|
140
|
+
Other Parameters:
|
|
141
|
+
hrp (str) : Expected HRP
|
|
142
|
+
net_ver (bytes): Expected net address version
|
|
143
|
+
|
|
144
|
+
Returns:
|
|
145
|
+
bytes: Public key hash bytes
|
|
146
|
+
|
|
147
|
+
Raises:
|
|
148
|
+
ValueError: If the address encoding is not valid
|
|
149
|
+
"""
|
|
150
|
+
hrp = kwargs["hrp"]
|
|
151
|
+
net_ver_bytes = kwargs["net_ver"]
|
|
152
|
+
|
|
153
|
+
try:
|
|
154
|
+
net_ver_bytes_got, addr_dec_bytes = BchBech32Decoder.Decode(hrp, addr)
|
|
155
|
+
except Bech32ChecksumError as ex:
|
|
156
|
+
raise ValueError("Invalid bech32 checksum") from ex
|
|
157
|
+
|
|
158
|
+
# Check net version
|
|
159
|
+
if net_ver_bytes != net_ver_bytes_got:
|
|
160
|
+
raise ValueError(f"Invalid net version (expected {BytesUtils.ToHexString(net_ver_bytes)}, "
|
|
161
|
+
f"got {BytesUtils.ToHexString(net_ver_bytes_got)})")
|
|
162
|
+
# Validate length
|
|
163
|
+
AddrDecUtils.ValidateLength(addr_dec_bytes,
|
|
164
|
+
Hash160.DigestSize())
|
|
165
|
+
return addr_dec_bytes
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
class BchP2PKHAddrEncoder(IAddrEncoder):
|
|
169
|
+
"""
|
|
170
|
+
Bitcoin Cash P2PKH address encoder class.
|
|
171
|
+
It allows the Bitcoin Cash P2PKH encoding.
|
|
172
|
+
"""
|
|
173
|
+
|
|
174
|
+
@staticmethod
|
|
175
|
+
def EncodeKey(pub_key: Union[bytes, IPublicKey],
|
|
176
|
+
**kwargs: Any) -> str:
|
|
177
|
+
"""
|
|
178
|
+
Encode a public key to Bitcoin Cash P2PKH address.
|
|
179
|
+
|
|
180
|
+
Args:
|
|
181
|
+
pub_key (bytes or IPublicKey): Public key bytes or object
|
|
182
|
+
|
|
183
|
+
Other Parameters:
|
|
184
|
+
hrp (str) : HRP
|
|
185
|
+
net_ver (bytes): Net address version
|
|
186
|
+
|
|
187
|
+
Returns:
|
|
188
|
+
str: Address string
|
|
189
|
+
|
|
190
|
+
Raises:
|
|
191
|
+
ValueError: If the public key is not valid
|
|
192
|
+
TypeError: If the public key is not secp256k1
|
|
193
|
+
"""
|
|
194
|
+
hrp = kwargs["hrp"]
|
|
195
|
+
net_ver_bytes = kwargs["net_ver"]
|
|
196
|
+
|
|
197
|
+
pub_key_obj = AddrKeyValidator.ValidateAndGetSecp256k1Key(pub_key)
|
|
198
|
+
return BchBech32Encoder.Encode(hrp,
|
|
199
|
+
net_ver_bytes,
|
|
200
|
+
Hash160.QuickDigest(pub_key_obj.RawCompressed().ToBytes()))
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
# Deprecated: only for compatibility, Encoder classes shall be used instead
|
|
204
|
+
P2PKHAddr = P2PKHAddrEncoder
|
|
205
|
+
BchP2PKHAddr = BchP2PKHAddrEncoder
|
|
@@ -0,0 +1,125 @@
|
|
|
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 utility functions for address decoding."""
|
|
22
|
+
|
|
23
|
+
# Imports
|
|
24
|
+
from typing import Callable, Tuple, Type, TypeVar, Union
|
|
25
|
+
|
|
26
|
+
from ..ecc import IPublicKey
|
|
27
|
+
from ..utils.misc import BytesUtils
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
BytesOrStr = TypeVar("BytesOrStr", bytes, str)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class AddrDecUtils:
|
|
34
|
+
"""Class container for address decoding utility functions."""
|
|
35
|
+
|
|
36
|
+
@staticmethod
|
|
37
|
+
def ValidateAndRemovePrefix(addr: BytesOrStr,
|
|
38
|
+
prefix: BytesOrStr) -> BytesOrStr:
|
|
39
|
+
"""
|
|
40
|
+
Validate and remove prefix from an address.
|
|
41
|
+
|
|
42
|
+
Args:
|
|
43
|
+
addr (bytes or str) : Address string or bytes
|
|
44
|
+
prefix (bytes or str): Address prefix
|
|
45
|
+
|
|
46
|
+
Returns:
|
|
47
|
+
bytes or str: Address string or bytes with prefix removed
|
|
48
|
+
|
|
49
|
+
Raises:
|
|
50
|
+
ValueError: If the prefix is not valid
|
|
51
|
+
"""
|
|
52
|
+
prefix_got = addr[:len(prefix)]
|
|
53
|
+
if prefix != prefix_got:
|
|
54
|
+
raise ValueError(f"Invalid prefix (expected {prefix!r}, got {prefix_got!r})")
|
|
55
|
+
return addr[len(prefix):]
|
|
56
|
+
|
|
57
|
+
@staticmethod
|
|
58
|
+
def ValidateLength(addr: Union[bytes, str],
|
|
59
|
+
len_exp: int) -> None:
|
|
60
|
+
"""
|
|
61
|
+
Validate address length.
|
|
62
|
+
|
|
63
|
+
Args:
|
|
64
|
+
addr (str) : Address string or bytes
|
|
65
|
+
len_exp (int): Expected address length
|
|
66
|
+
|
|
67
|
+
Raises:
|
|
68
|
+
ValueError: If the length is not valid
|
|
69
|
+
"""
|
|
70
|
+
if len(addr) != len_exp:
|
|
71
|
+
raise ValueError(f"Invalid length (expected {len_exp}, got {len(addr)})")
|
|
72
|
+
|
|
73
|
+
@staticmethod
|
|
74
|
+
def ValidatePubKey(pub_key_bytes: bytes,
|
|
75
|
+
pub_key_cls: Type[IPublicKey]) -> None:
|
|
76
|
+
"""
|
|
77
|
+
Validate address length.
|
|
78
|
+
|
|
79
|
+
Args:
|
|
80
|
+
pub_key_bytes (bytes) : Public key bytes
|
|
81
|
+
pub_key_cls (IPublicKey): Public key class type
|
|
82
|
+
|
|
83
|
+
Raises:
|
|
84
|
+
ValueError: If the public key is not valid
|
|
85
|
+
"""
|
|
86
|
+
if not pub_key_cls.IsValidBytes(pub_key_bytes):
|
|
87
|
+
raise ValueError(f"Invalid {pub_key_cls.CurveType()} "
|
|
88
|
+
f"public key {BytesUtils.ToHexString(pub_key_bytes)}")
|
|
89
|
+
|
|
90
|
+
@staticmethod
|
|
91
|
+
def ValidateChecksum(payload_bytes: bytes,
|
|
92
|
+
checksum_bytes_exp: bytes,
|
|
93
|
+
checksum_fct: Callable[[bytes], bytes]) -> None:
|
|
94
|
+
"""
|
|
95
|
+
Validate address checksum.
|
|
96
|
+
|
|
97
|
+
Args:
|
|
98
|
+
payload_bytes (bytes) : Payload bytes
|
|
99
|
+
checksum_bytes_exp (bytes): Expected checksum bytes
|
|
100
|
+
checksum_fct (function) : Function for computing checksum
|
|
101
|
+
|
|
102
|
+
Raises:
|
|
103
|
+
ValueError: If the computed checksum is not equal tot he specified one
|
|
104
|
+
"""
|
|
105
|
+
checksum_bytes_got = checksum_fct(payload_bytes)
|
|
106
|
+
if checksum_bytes_exp != checksum_bytes_got:
|
|
107
|
+
raise ValueError(f"Invalid checksum (expected {BytesUtils.ToHexString(checksum_bytes_exp)}, "
|
|
108
|
+
f"got {BytesUtils.ToHexString(checksum_bytes_got)})")
|
|
109
|
+
|
|
110
|
+
@staticmethod
|
|
111
|
+
def SplitPartsByChecksum(addr_bytes: bytes,
|
|
112
|
+
checksum_len: int) -> Tuple[bytes, bytes]:
|
|
113
|
+
"""
|
|
114
|
+
Split address in two parts, considering the checksum at the end of it.
|
|
115
|
+
|
|
116
|
+
Args:
|
|
117
|
+
addr_bytes (bytes): Address bytes
|
|
118
|
+
checksum_len (int): Checksum length
|
|
119
|
+
|
|
120
|
+
Returns:
|
|
121
|
+
tuple[bytes, bytes]: Payload bytes (index 0) and checksum bytes (index 1)
|
|
122
|
+
"""
|
|
123
|
+
checksum_bytes = addr_bytes[-1 * checksum_len:]
|
|
124
|
+
payload_bytes = addr_bytes[:-1 * checksum_len]
|
|
125
|
+
return payload_bytes, checksum_bytes
|
|
@@ -0,0 +1,162 @@
|
|
|
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 utility functions for validating address public keys."""
|
|
22
|
+
|
|
23
|
+
# Imports
|
|
24
|
+
from typing import Type, Union
|
|
25
|
+
|
|
26
|
+
from ..ecc import (
|
|
27
|
+
Secp256k1PublicKey, IPublicKey,
|
|
28
|
+
# Ed25519Blake2bPublicKey, Ed25519MoneroPublicKey, Ed25519PublicKey, EllipticCurveGetter,
|
|
29
|
+
# Nist256p1PublicKey, Secp256k1PublicKey, Sr25519PublicKey
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class AddrKeyValidator:
|
|
34
|
+
"""Class container for address utility functions."""
|
|
35
|
+
|
|
36
|
+
# @staticmethod
|
|
37
|
+
# def ValidateAndGetEd25519Key(pub_key: Union[bytes, IPublicKey]) -> IPublicKey:
|
|
38
|
+
# """
|
|
39
|
+
# Validate and get a ed25519 public key.
|
|
40
|
+
|
|
41
|
+
# Args:
|
|
42
|
+
# pub_key (bytes or IPublicKey object): Public key bytes or object
|
|
43
|
+
|
|
44
|
+
# Returns:
|
|
45
|
+
# IPublicKey object: IPublicKey object
|
|
46
|
+
|
|
47
|
+
# Raises:
|
|
48
|
+
# TypeError: If the public key is not ed25519
|
|
49
|
+
# ValueError: If the public key is not valid
|
|
50
|
+
# """
|
|
51
|
+
# return AddrKeyValidator.__ValidateAndGetGenericKey(pub_key, Ed25519PublicKey)
|
|
52
|
+
|
|
53
|
+
# @staticmethod
|
|
54
|
+
# def ValidateAndGetEd25519Blake2bKey(pub_key: Union[bytes, IPublicKey]) -> IPublicKey:
|
|
55
|
+
# """
|
|
56
|
+
# Validate and get a ed25519-blake2b public key.
|
|
57
|
+
|
|
58
|
+
# Args:
|
|
59
|
+
# pub_key (bytes or IPublicKey object): Public key bytes or object
|
|
60
|
+
|
|
61
|
+
# Returns:
|
|
62
|
+
# IPublicKey object: IPublicKey object
|
|
63
|
+
|
|
64
|
+
# Raises:
|
|
65
|
+
# TypeError: If the public key is not ed25519-blake2b
|
|
66
|
+
# ValueError: If the public key is not valid
|
|
67
|
+
# """
|
|
68
|
+
# return AddrKeyValidator.__ValidateAndGetGenericKey(pub_key, Ed25519Blake2bPublicKey)
|
|
69
|
+
|
|
70
|
+
# @staticmethod
|
|
71
|
+
# def ValidateAndGetEd25519MoneroKey(pub_key: Union[bytes, IPublicKey]) -> IPublicKey:
|
|
72
|
+
# """
|
|
73
|
+
# Validate and get a ed25519-monero public key.
|
|
74
|
+
|
|
75
|
+
# Args:
|
|
76
|
+
# pub_key (bytes or IPublicKey object): Public key bytes or object
|
|
77
|
+
|
|
78
|
+
# Returns:
|
|
79
|
+
# IPublicKey object: IPublicKey object
|
|
80
|
+
|
|
81
|
+
# Raises:
|
|
82
|
+
# TypeError: If the public key is not ed25519-monero
|
|
83
|
+
# ValueError: If the public key is not valid
|
|
84
|
+
# """
|
|
85
|
+
# return AddrKeyValidator.__ValidateAndGetGenericKey(pub_key, Ed25519MoneroPublicKey)
|
|
86
|
+
|
|
87
|
+
# @staticmethod
|
|
88
|
+
# def ValidateAndGetNist256p1Key(pub_key: Union[bytes, IPublicKey]) -> IPublicKey:
|
|
89
|
+
# """
|
|
90
|
+
# Validate and get a nist256p1 public key.
|
|
91
|
+
|
|
92
|
+
# Args:
|
|
93
|
+
# pub_key (bytes or IPublicKey object): Public key bytes or object
|
|
94
|
+
|
|
95
|
+
# Returns:
|
|
96
|
+
# IPublicKey object: IPublicKey object
|
|
97
|
+
|
|
98
|
+
# Raises:
|
|
99
|
+
# TypeError: If the public key is not nist256p1
|
|
100
|
+
# ValueError: If the public key is not valid
|
|
101
|
+
# """
|
|
102
|
+
# return AddrKeyValidator.__ValidateAndGetGenericKey(pub_key, Nist256p1PublicKey)
|
|
103
|
+
|
|
104
|
+
@staticmethod
|
|
105
|
+
def ValidateAndGetSecp256k1Key(pub_key: Union[bytes, IPublicKey]) -> IPublicKey:
|
|
106
|
+
"""
|
|
107
|
+
Validate and get a secp256k1 public key.
|
|
108
|
+
|
|
109
|
+
Args:
|
|
110
|
+
pub_key (bytes or IPublicKey object): Public key bytes or object
|
|
111
|
+
|
|
112
|
+
Returns:
|
|
113
|
+
IPublicKey object: IPublicKey object
|
|
114
|
+
|
|
115
|
+
Raises:
|
|
116
|
+
TypeError: If the public key is not secp256k1
|
|
117
|
+
ValueError: If the public key is not valid
|
|
118
|
+
"""
|
|
119
|
+
return AddrKeyValidator.__ValidateAndGetGenericKey(pub_key, Secp256k1PublicKey)
|
|
120
|
+
|
|
121
|
+
# @staticmethod
|
|
122
|
+
# def ValidateAndGetSr25519Key(pub_key: Union[bytes, IPublicKey]) -> IPublicKey:
|
|
123
|
+
# """
|
|
124
|
+
# Validate and get a sr25519 public key.
|
|
125
|
+
|
|
126
|
+
# Args:
|
|
127
|
+
# pub_key (bytes or IPublicKey object): Public key bytes or object
|
|
128
|
+
|
|
129
|
+
# Returns:
|
|
130
|
+
# IPublicKey object: IPublicKey object
|
|
131
|
+
|
|
132
|
+
# Raises:
|
|
133
|
+
# TypeError: If the public key is not sr25519
|
|
134
|
+
# ValueError: If the public key is not valid
|
|
135
|
+
# """
|
|
136
|
+
# return AddrKeyValidator.__ValidateAndGetGenericKey(pub_key, Sr25519PublicKey)
|
|
137
|
+
|
|
138
|
+
@staticmethod
|
|
139
|
+
def __ValidateAndGetGenericKey(pub_key: Union[bytes, IPublicKey],
|
|
140
|
+
pub_key_cls: Type[IPublicKey]) -> IPublicKey:
|
|
141
|
+
"""
|
|
142
|
+
Validate and get a generic public key.
|
|
143
|
+
|
|
144
|
+
Args:
|
|
145
|
+
pub_key (bytes or IPublicKey object): Public key bytes or object
|
|
146
|
+
pub_key_cls (IPublicKey) : Public key class type
|
|
147
|
+
|
|
148
|
+
Returns:
|
|
149
|
+
IPublicKey object: IPublicKey object
|
|
150
|
+
|
|
151
|
+
Raises:
|
|
152
|
+
TypeError: If the public key is not of the correct class type
|
|
153
|
+
ValueError: If the public key is not valid
|
|
154
|
+
"""
|
|
155
|
+
if isinstance(pub_key, bytes):
|
|
156
|
+
pub_key = pub_key_cls.FromBytes(pub_key)
|
|
157
|
+
elif not isinstance(pub_key, pub_key_cls):
|
|
158
|
+
curve = EllipticCurveGetter.FromType(pub_key_cls.CurveType())
|
|
159
|
+
raise TypeError(f"A {curve.Name()} public key is required"
|
|
160
|
+
f"(expected: {pub_key_cls}, got: {type(pub_key)}")
|
|
161
|
+
|
|
162
|
+
return pub_key
|