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,294 @@
|
|
|
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 BIP32 extended key serialization/deserialization."""
|
|
22
|
+
|
|
23
|
+
# Imports
|
|
24
|
+
from typing import Tuple
|
|
25
|
+
|
|
26
|
+
from ..base58 import Base58Decoder, Base58Encoder
|
|
27
|
+
from .bip32_const import Bip32Const
|
|
28
|
+
from .bip32_ex import Bip32KeyError
|
|
29
|
+
from .bip32_key_data import Bip32ChainCode, Bip32Depth, Bip32FingerPrint, Bip32KeyData, Bip32KeyIndex
|
|
30
|
+
from .bip32_key_net_ver import Bip32KeyNetVersions
|
|
31
|
+
from ..ecc import IPrivateKey, IPublicKey
|
|
32
|
+
from ..utils.misc import BytesUtils
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class Bip32KeySerConst:
|
|
36
|
+
"""Class container for BIP32 key serialize constants."""
|
|
37
|
+
|
|
38
|
+
# Serialized public key length in bytes
|
|
39
|
+
SERIALIZED_PUB_KEY_BYTE_LEN: int = 78
|
|
40
|
+
# Serialized private key length in bytes
|
|
41
|
+
SERIALIZED_PRIV_KEY_BYTE_LEN: Tuple[int, int] = (78, 110)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class _Bip32KeySerializer:
|
|
45
|
+
"""
|
|
46
|
+
BIP32 key serializer class.
|
|
47
|
+
It serializes private/public keys.
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
@staticmethod
|
|
51
|
+
def Serialize(key_bytes: bytes,
|
|
52
|
+
key_data: Bip32KeyData,
|
|
53
|
+
key_net_ver_bytes: bytes) -> str:
|
|
54
|
+
"""
|
|
55
|
+
Serialize the specified key bytes.
|
|
56
|
+
|
|
57
|
+
Args:
|
|
58
|
+
key_bytes (bytes) : Key bytes
|
|
59
|
+
key_data (BipKeyData object): Key data
|
|
60
|
+
key_net_ver_bytes (bytes) : Key net version bytes
|
|
61
|
+
|
|
62
|
+
Returns:
|
|
63
|
+
str: Serialized key
|
|
64
|
+
"""
|
|
65
|
+
|
|
66
|
+
# Serialize key
|
|
67
|
+
ser_key = (
|
|
68
|
+
key_net_ver_bytes
|
|
69
|
+
+ bytes(key_data.Depth()) + bytes(key_data.ParentFingerPrint()) + bytes(key_data.Index())
|
|
70
|
+
+ bytes(key_data.ChainCode()) + key_bytes
|
|
71
|
+
)
|
|
72
|
+
# Encode it
|
|
73
|
+
return Base58Encoder.CheckEncode(ser_key)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class Bip32PrivateKeySerializer:
|
|
77
|
+
"""
|
|
78
|
+
BIP32 private key serializer class.
|
|
79
|
+
It serializes private keys.
|
|
80
|
+
"""
|
|
81
|
+
|
|
82
|
+
@staticmethod
|
|
83
|
+
def Serialize(priv_key: IPrivateKey,
|
|
84
|
+
key_data: Bip32KeyData,
|
|
85
|
+
key_net_ver: Bip32KeyNetVersions = Bip32Const.MAIN_NET_KEY_NET_VERSIONS) -> str:
|
|
86
|
+
"""
|
|
87
|
+
Serialize a private key.
|
|
88
|
+
|
|
89
|
+
Args:
|
|
90
|
+
priv_key (IPrivateKey object) : IPrivateKey object
|
|
91
|
+
key_data (BipKeyData object) : Key data
|
|
92
|
+
key_net_ver (Bip32KeyNetVersions object, optional): Key net versions (BIP32 main net version by default)
|
|
93
|
+
|
|
94
|
+
Returns:
|
|
95
|
+
str: Serialized private key
|
|
96
|
+
"""
|
|
97
|
+
return _Bip32KeySerializer.Serialize(b"\x00" + priv_key.Raw().ToBytes(),
|
|
98
|
+
key_data,
|
|
99
|
+
key_net_ver.Private())
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class Bip32PublicKeySerializer:
|
|
103
|
+
"""
|
|
104
|
+
BIP32 public key serializer class.
|
|
105
|
+
It serializes public keys.
|
|
106
|
+
"""
|
|
107
|
+
|
|
108
|
+
@staticmethod
|
|
109
|
+
def Serialize(pub_key: IPublicKey,
|
|
110
|
+
key_data: Bip32KeyData,
|
|
111
|
+
key_net_ver: Bip32KeyNetVersions = Bip32Const.MAIN_NET_KEY_NET_VERSIONS) -> str:
|
|
112
|
+
"""
|
|
113
|
+
Serialize a public key.
|
|
114
|
+
|
|
115
|
+
Args:
|
|
116
|
+
pub_key (IPublicKey object) : IPublicKey object
|
|
117
|
+
key_data (BipKeyData object) : Key data
|
|
118
|
+
key_net_ver (Bip32KeyNetVersions object, optional): Key net versions (BIP32 main net version by default)
|
|
119
|
+
|
|
120
|
+
Returns:
|
|
121
|
+
str: Serialized public key
|
|
122
|
+
"""
|
|
123
|
+
return _Bip32KeySerializer.Serialize(pub_key.RawCompressed().ToBytes(),
|
|
124
|
+
key_data,
|
|
125
|
+
key_net_ver.Public())
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
class Bip32DeserializedKey:
|
|
129
|
+
"""
|
|
130
|
+
BIP32 deserialized key class.
|
|
131
|
+
It represents a key deserialized with the Bip32KeyDeserializer.
|
|
132
|
+
"""
|
|
133
|
+
|
|
134
|
+
m_key_bytes: bytes
|
|
135
|
+
m_key_data: Bip32KeyData
|
|
136
|
+
m_is_public: bool
|
|
137
|
+
|
|
138
|
+
def __init__(self,
|
|
139
|
+
key_bytes: bytes,
|
|
140
|
+
key_data: Bip32KeyData,
|
|
141
|
+
is_public: bool) -> None:
|
|
142
|
+
"""
|
|
143
|
+
Construct class.
|
|
144
|
+
|
|
145
|
+
Args:
|
|
146
|
+
key_bytes (bytes) : Key bytes
|
|
147
|
+
key_data (BipKeyData object): Key data
|
|
148
|
+
is_public (bool) : True if the key is public, false otherwise
|
|
149
|
+
|
|
150
|
+
Returns:
|
|
151
|
+
str: Serialized public key
|
|
152
|
+
"""
|
|
153
|
+
self.m_key_bytes = key_bytes
|
|
154
|
+
self.m_key_data = key_data
|
|
155
|
+
self.m_is_public = is_public
|
|
156
|
+
|
|
157
|
+
def KeyBytes(self) -> bytes:
|
|
158
|
+
"""
|
|
159
|
+
Get key bytes.
|
|
160
|
+
|
|
161
|
+
Returns:
|
|
162
|
+
bytes: Key bytes
|
|
163
|
+
"""
|
|
164
|
+
return self.m_key_bytes
|
|
165
|
+
|
|
166
|
+
def KeyData(self) -> Bip32KeyData:
|
|
167
|
+
"""
|
|
168
|
+
Get key data.
|
|
169
|
+
|
|
170
|
+
Returns:
|
|
171
|
+
Bip32KeyData object: Bip32KeyData object
|
|
172
|
+
"""
|
|
173
|
+
return self.m_key_data
|
|
174
|
+
|
|
175
|
+
def IsPublic(self) -> bool:
|
|
176
|
+
"""
|
|
177
|
+
Get if public.
|
|
178
|
+
|
|
179
|
+
Returns:
|
|
180
|
+
bool: True if the key is public, false otherwise
|
|
181
|
+
"""
|
|
182
|
+
return self.m_is_public
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
class Bip32KeyDeserializer:
|
|
186
|
+
"""
|
|
187
|
+
BIP32 key deserializer class.
|
|
188
|
+
It deserializes an extended key.
|
|
189
|
+
"""
|
|
190
|
+
|
|
191
|
+
@classmethod
|
|
192
|
+
def DeserializeKey(cls,
|
|
193
|
+
ser_key_str: str,
|
|
194
|
+
key_net_ver: Bip32KeyNetVersions = Bip32Const.MAIN_NET_KEY_NET_VERSIONS) -> Bip32DeserializedKey:
|
|
195
|
+
"""
|
|
196
|
+
Deserialize a key.
|
|
197
|
+
|
|
198
|
+
Args:
|
|
199
|
+
ser_key_str (str) : Serialized key string
|
|
200
|
+
key_net_ver (Bip32KeyNetVersions object, optional): Key net versions (BIP32 main net version by default)
|
|
201
|
+
|
|
202
|
+
Returns:
|
|
203
|
+
Bip32DeserializedKey object: Bip32DeserializedKey object
|
|
204
|
+
|
|
205
|
+
Raises:
|
|
206
|
+
Bip32KeyError: If the key is not valid
|
|
207
|
+
"""
|
|
208
|
+
|
|
209
|
+
# Decode key
|
|
210
|
+
ser_key_bytes = Base58Decoder.CheckDecode(ser_key_str)
|
|
211
|
+
|
|
212
|
+
# Get if key is public/private depending on the net version
|
|
213
|
+
is_public = cls.__GetIfPublic(ser_key_bytes, key_net_ver)
|
|
214
|
+
|
|
215
|
+
# Validate length
|
|
216
|
+
if is_public and len(ser_key_bytes) != Bip32KeySerConst.SERIALIZED_PUB_KEY_BYTE_LEN:
|
|
217
|
+
raise Bip32KeyError(f"Invalid extended public key (wrong length: {len(ser_key_bytes)})")
|
|
218
|
+
if not is_public and len(ser_key_bytes) not in Bip32KeySerConst.SERIALIZED_PRIV_KEY_BYTE_LEN:
|
|
219
|
+
raise Bip32KeyError(f"Invalid extended private key (wrong length: {len(ser_key_bytes)})")
|
|
220
|
+
|
|
221
|
+
# Get parts back
|
|
222
|
+
key_bytes, key_data = cls.__GetPartsFromBytes(ser_key_bytes, is_public)
|
|
223
|
+
|
|
224
|
+
return Bip32DeserializedKey(key_bytes, key_data, is_public)
|
|
225
|
+
|
|
226
|
+
@staticmethod
|
|
227
|
+
def __GetIfPublic(ser_key_bytes: bytes,
|
|
228
|
+
key_net_ver: Bip32KeyNetVersions) -> bool:
|
|
229
|
+
"""
|
|
230
|
+
Get if the key is public.
|
|
231
|
+
|
|
232
|
+
Args:
|
|
233
|
+
ser_key_bytes (bytes) : Serialized key bytes
|
|
234
|
+
key_net_ver (Bip32KeyNetVersions object): Key net versions
|
|
235
|
+
|
|
236
|
+
Returns:
|
|
237
|
+
bool: True if public, false otherwise
|
|
238
|
+
|
|
239
|
+
Raises:
|
|
240
|
+
Bip32KeyError: If the key net version is not valid
|
|
241
|
+
"""
|
|
242
|
+
key_net_ver_got = ser_key_bytes[:Bip32KeyNetVersions.Length()]
|
|
243
|
+
if key_net_ver_got == key_net_ver.Public():
|
|
244
|
+
is_public = True
|
|
245
|
+
elif key_net_ver_got == key_net_ver.Private():
|
|
246
|
+
is_public = False
|
|
247
|
+
else:
|
|
248
|
+
raise Bip32KeyError(
|
|
249
|
+
f"Invalid extended key (wrong net version: {BytesUtils.ToHexString(key_net_ver_got)})"
|
|
250
|
+
)
|
|
251
|
+
return is_public
|
|
252
|
+
|
|
253
|
+
@staticmethod
|
|
254
|
+
def __GetPartsFromBytes(ser_key_bytes: bytes,
|
|
255
|
+
is_public: bool) -> Tuple[bytes, Bip32KeyData]:
|
|
256
|
+
"""
|
|
257
|
+
Get back key parts from serialized key bytes.
|
|
258
|
+
|
|
259
|
+
Args:
|
|
260
|
+
ser_key_bytes (bytes): Serialized key bytes
|
|
261
|
+
is_public (bool) : True if the key is public, false otherwise
|
|
262
|
+
|
|
263
|
+
Returns:
|
|
264
|
+
tuple[bytes, Bip32KeyData]: key bytes (index 0) and key data (index 1)
|
|
265
|
+
|
|
266
|
+
Raises:
|
|
267
|
+
Bip32KeyError: If the private key first byte is not zero
|
|
268
|
+
"""
|
|
269
|
+
|
|
270
|
+
# Compute indexes
|
|
271
|
+
depth_idx = Bip32KeyNetVersions.Length()
|
|
272
|
+
fprint_idx = depth_idx + Bip32Depth.FixedLength()
|
|
273
|
+
key_index_idx = fprint_idx + Bip32FingerPrint.FixedLength()
|
|
274
|
+
chain_code_idx = key_index_idx + Bip32KeyIndex.FixedLength()
|
|
275
|
+
key_idx = chain_code_idx + Bip32ChainCode.FixedLength()
|
|
276
|
+
|
|
277
|
+
# Get parts
|
|
278
|
+
depth = ser_key_bytes[depth_idx]
|
|
279
|
+
fprint_bytes = ser_key_bytes[fprint_idx:key_index_idx]
|
|
280
|
+
key_index_bytes = ser_key_bytes[key_index_idx:chain_code_idx]
|
|
281
|
+
chain_code_bytes = ser_key_bytes[chain_code_idx:key_idx]
|
|
282
|
+
key_bytes = ser_key_bytes[key_idx:]
|
|
283
|
+
key_data = Bip32KeyData(Bip32Depth(depth),
|
|
284
|
+
Bip32KeyIndex.FromBytes(key_index_bytes),
|
|
285
|
+
Bip32ChainCode(chain_code_bytes),
|
|
286
|
+
Bip32FingerPrint(fprint_bytes))
|
|
287
|
+
|
|
288
|
+
# If private key, the first byte shall be zero and shall be removed
|
|
289
|
+
if not is_public:
|
|
290
|
+
if key_bytes[0] != 0:
|
|
291
|
+
raise Bip32KeyError(f"Invalid extended private key (wrong secret: {key_bytes[0]})")
|
|
292
|
+
key_bytes = key_bytes[1:]
|
|
293
|
+
|
|
294
|
+
return key_bytes, key_data
|