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,47 @@
|
|
|
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 SLIP-0010 keys derivation."""
|
|
22
|
+
|
|
23
|
+
# Imports
|
|
24
|
+
from abc import ABC, abstractmethod
|
|
25
|
+
from typing import Tuple
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class IBip32MstKeyGenerator(ABC):
|
|
29
|
+
"""Interface for generic BIP32 master key generator."""
|
|
30
|
+
|
|
31
|
+
@classmethod
|
|
32
|
+
@abstractmethod
|
|
33
|
+
def GenerateFromSeed(cls,
|
|
34
|
+
seed_bytes: bytes) -> Tuple[bytes, bytes]:
|
|
35
|
+
"""
|
|
36
|
+
Generate a master key from the specified seed.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
seed_bytes (bytes): Seed bytes
|
|
40
|
+
|
|
41
|
+
Returns:
|
|
42
|
+
tuple[bytes, bytes]: Private key bytes (index 0) and chain code bytes (index 1)
|
|
43
|
+
|
|
44
|
+
Raises:
|
|
45
|
+
Bip32KeyError: If the seed is not suitable for master key generation
|
|
46
|
+
ValueError: If seed length is not valid
|
|
47
|
+
"""
|
|
@@ -0,0 +1,35 @@
|
|
|
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 BIP32 constants."""
|
|
22
|
+
|
|
23
|
+
# Imports
|
|
24
|
+
from .bip32_key_net_ver import Bip32KeyNetVersions
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class Bip32Const:
|
|
28
|
+
"""Class container for BIP32 constants."""
|
|
29
|
+
|
|
30
|
+
# Main net key net version (xpub / xprv)
|
|
31
|
+
MAIN_NET_KEY_NET_VERSIONS: Bip32KeyNetVersions = Bip32KeyNetVersions(b"\x04\x88\xb2\x1e", b"\x04\x88\xad\xe4")
|
|
32
|
+
# Test net key net version (tpub / tprv)
|
|
33
|
+
TEST_NET_KEY_NET_VERSIONS: Bip32KeyNetVersions = Bip32KeyNetVersions(b"\x04\x35\x87\xcf", b"\x04\x35\x83\x94")
|
|
34
|
+
# Key net version for BIP32 Kholaw that uses 64-byte private keys (xpub / xprv)
|
|
35
|
+
# KHOLAW_KEY_NET_VERSIONS: Bip32KeyNetVersions = Bip32KeyNetVersions(b"\x04\x88\xb2\x1e", b"\x0f\x43\x31\xd4")
|
|
@@ -0,0 +1,29 @@
|
|
|
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 BIP32 exceptions."""
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class Bip32KeyError(Exception):
|
|
25
|
+
"""Exception in case of key error."""
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class Bip32PathError(Exception):
|
|
29
|
+
"""Exception in case of path error."""
|
|
@@ -0,0 +1,500 @@
|
|
|
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 classes for BIP32 key data."""
|
|
22
|
+
|
|
23
|
+
# Imports
|
|
24
|
+
from __future__ import annotations
|
|
25
|
+
|
|
26
|
+
from typing import Union
|
|
27
|
+
|
|
28
|
+
from ..utils.misc import BitUtils, BytesUtils, DataBytes, IntegerUtils
|
|
29
|
+
from ..utils.typing import Literal
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class Bip32KeyDataConst:
|
|
33
|
+
"""Class container for BIP32 key data constants."""
|
|
34
|
+
|
|
35
|
+
# Chaincode length in bytes
|
|
36
|
+
CHAINCODE_BYTE_LEN: int = 32
|
|
37
|
+
# Depth length in bytes
|
|
38
|
+
DEPTH_BYTE_LEN: int = 1
|
|
39
|
+
# Fingerprint length in bytes
|
|
40
|
+
FINGERPRINT_BYTE_LEN: int = 4
|
|
41
|
+
# Fingerprint of master key
|
|
42
|
+
FINGERPRINT_MASTER_KEY: bytes = b"\x00\x00\x00\x00"
|
|
43
|
+
# Key index length in bytes
|
|
44
|
+
KEY_INDEX_BYTE_LEN: int = 4
|
|
45
|
+
# Key index maximum value
|
|
46
|
+
KEY_INDEX_MAX_VAL: int = 2**32 - 1
|
|
47
|
+
# Key index hardened bit number
|
|
48
|
+
KEY_INDEX_HARDENED_BIT_NUM: int = 31
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class Bip32ChainCode(DataBytes):
|
|
52
|
+
"""
|
|
53
|
+
BIP32 chaincode class.
|
|
54
|
+
It represents a BIP32 chaincode.
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
def __init__(self,
|
|
58
|
+
chaincode: bytes = b"\x00" * Bip32KeyDataConst.CHAINCODE_BYTE_LEN) -> None:
|
|
59
|
+
"""
|
|
60
|
+
Construct class.
|
|
61
|
+
|
|
62
|
+
Args:
|
|
63
|
+
chaincode (bytes, optional): Fingerprint bytes (default: zero)
|
|
64
|
+
|
|
65
|
+
Raises:
|
|
66
|
+
ValueError: If the chain code length is not valid
|
|
67
|
+
"""
|
|
68
|
+
if len(chaincode) != self.FixedLength():
|
|
69
|
+
raise ValueError(f"Invalid chaincode length ({len(chaincode)})")
|
|
70
|
+
super().__init__(chaincode)
|
|
71
|
+
|
|
72
|
+
@staticmethod
|
|
73
|
+
def FixedLength() -> int:
|
|
74
|
+
"""
|
|
75
|
+
Get the fixed length in bytes.
|
|
76
|
+
|
|
77
|
+
Returns:
|
|
78
|
+
int: Length in bytes
|
|
79
|
+
"""
|
|
80
|
+
return Bip32KeyDataConst.CHAINCODE_BYTE_LEN
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class Bip32FingerPrint(DataBytes):
|
|
84
|
+
"""
|
|
85
|
+
BIP32 fingerprint class.
|
|
86
|
+
It represents a BIP32 fingerprint.
|
|
87
|
+
"""
|
|
88
|
+
|
|
89
|
+
def __init__(self,
|
|
90
|
+
fprint: bytes = Bip32KeyDataConst.FINGERPRINT_MASTER_KEY) -> None:
|
|
91
|
+
"""
|
|
92
|
+
Construct class.
|
|
93
|
+
|
|
94
|
+
Args:
|
|
95
|
+
fprint (bytes, optional): Fingerprint bytes (default: master key)
|
|
96
|
+
|
|
97
|
+
Raises:
|
|
98
|
+
ValueError: If the chain code length is not valid
|
|
99
|
+
"""
|
|
100
|
+
if len(fprint) < self.FixedLength():
|
|
101
|
+
raise ValueError(f"Invalid fingerprint length ({len(fprint)})")
|
|
102
|
+
super().__init__(fprint[:Bip32KeyDataConst.FINGERPRINT_BYTE_LEN])
|
|
103
|
+
|
|
104
|
+
@staticmethod
|
|
105
|
+
def FixedLength() -> int:
|
|
106
|
+
"""
|
|
107
|
+
Get the fixed length in bytes.
|
|
108
|
+
|
|
109
|
+
Returns:
|
|
110
|
+
int: Length in bytes
|
|
111
|
+
"""
|
|
112
|
+
return Bip32KeyDataConst.FINGERPRINT_BYTE_LEN
|
|
113
|
+
|
|
114
|
+
def IsMasterKey(self) -> bool:
|
|
115
|
+
"""
|
|
116
|
+
Get if the fingerprint corresponds to a master key.
|
|
117
|
+
|
|
118
|
+
Returns:
|
|
119
|
+
bool: True if it corresponds to a master key, false otherwise
|
|
120
|
+
"""
|
|
121
|
+
return self.ToBytes() == Bip32KeyDataConst.FINGERPRINT_MASTER_KEY
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
class Bip32Depth:
|
|
125
|
+
"""
|
|
126
|
+
BIP32 depth class.
|
|
127
|
+
It represents a BIP32 depth.
|
|
128
|
+
"""
|
|
129
|
+
|
|
130
|
+
m_depth: int
|
|
131
|
+
|
|
132
|
+
def __init__(self,
|
|
133
|
+
depth: int) -> None:
|
|
134
|
+
"""
|
|
135
|
+
Construct class.
|
|
136
|
+
|
|
137
|
+
Args:
|
|
138
|
+
depth (int): Depth
|
|
139
|
+
|
|
140
|
+
Raises:
|
|
141
|
+
ValueError: If the depth value is not valid
|
|
142
|
+
"""
|
|
143
|
+
if depth < 0:
|
|
144
|
+
raise ValueError(f"Invalid depth ({depth})")
|
|
145
|
+
self.m_depth = depth
|
|
146
|
+
|
|
147
|
+
@staticmethod
|
|
148
|
+
def FixedLength() -> int:
|
|
149
|
+
"""
|
|
150
|
+
Get the fixed length in bytes.
|
|
151
|
+
|
|
152
|
+
Returns:
|
|
153
|
+
int: Length in bytes
|
|
154
|
+
"""
|
|
155
|
+
return Bip32KeyDataConst.DEPTH_BYTE_LEN
|
|
156
|
+
|
|
157
|
+
def Increase(self) -> Bip32Depth:
|
|
158
|
+
"""
|
|
159
|
+
Get a new object with increased depth.
|
|
160
|
+
|
|
161
|
+
Returns:
|
|
162
|
+
Bip32Depth object: Bip32Depth object
|
|
163
|
+
"""
|
|
164
|
+
return Bip32Depth(self.m_depth + 1)
|
|
165
|
+
|
|
166
|
+
def ToBytes(self) -> bytes:
|
|
167
|
+
"""
|
|
168
|
+
Get the depth as bytes.
|
|
169
|
+
|
|
170
|
+
Returns:
|
|
171
|
+
bytes: Depth bytes
|
|
172
|
+
"""
|
|
173
|
+
return IntegerUtils.ToBytes(self.m_depth, bytes_num=self.FixedLength())
|
|
174
|
+
|
|
175
|
+
def ToInt(self) -> int:
|
|
176
|
+
"""
|
|
177
|
+
Get the depth as integer.
|
|
178
|
+
|
|
179
|
+
Returns:
|
|
180
|
+
int: Depth index
|
|
181
|
+
"""
|
|
182
|
+
return int(self.m_depth)
|
|
183
|
+
|
|
184
|
+
def __int__(self) -> int:
|
|
185
|
+
"""
|
|
186
|
+
Get the depth as integer.
|
|
187
|
+
|
|
188
|
+
Returns:
|
|
189
|
+
int: Depth index
|
|
190
|
+
"""
|
|
191
|
+
return self.ToInt()
|
|
192
|
+
|
|
193
|
+
def __bytes__(self) -> bytes:
|
|
194
|
+
"""
|
|
195
|
+
Get the depth as bytes.
|
|
196
|
+
|
|
197
|
+
Returns:
|
|
198
|
+
bytes: Depth bytes
|
|
199
|
+
"""
|
|
200
|
+
return self.ToBytes()
|
|
201
|
+
|
|
202
|
+
def __eq__(self,
|
|
203
|
+
other: object) -> bool:
|
|
204
|
+
"""
|
|
205
|
+
Equality operator.
|
|
206
|
+
|
|
207
|
+
Args:
|
|
208
|
+
other (int or Bip32Depth object): Other object to compare
|
|
209
|
+
|
|
210
|
+
Returns:
|
|
211
|
+
bool: True if equal false otherwise
|
|
212
|
+
|
|
213
|
+
Raises:
|
|
214
|
+
TypeError: If the other object is not of the correct type
|
|
215
|
+
"""
|
|
216
|
+
if not isinstance(other, (int, Bip32Depth)):
|
|
217
|
+
raise TypeError(f"Invalid type for checking equality ({type(other)})")
|
|
218
|
+
|
|
219
|
+
if isinstance(other, int):
|
|
220
|
+
return self.m_depth == other
|
|
221
|
+
return self.m_depth == other.m_depth
|
|
222
|
+
|
|
223
|
+
def __gt__(self,
|
|
224
|
+
other: Union[int, Bip32Depth]) -> bool:
|
|
225
|
+
"""
|
|
226
|
+
Greater than operator.
|
|
227
|
+
|
|
228
|
+
Args:
|
|
229
|
+
other (int or Bip32Depth object): Other value to compare
|
|
230
|
+
|
|
231
|
+
Returns:
|
|
232
|
+
bool: True if greater false otherwise
|
|
233
|
+
"""
|
|
234
|
+
if isinstance(other, int):
|
|
235
|
+
return self.m_depth > other
|
|
236
|
+
return self.m_depth > other.m_depth
|
|
237
|
+
|
|
238
|
+
def __lt__(self,
|
|
239
|
+
other: Union[int, Bip32Depth]) -> bool:
|
|
240
|
+
"""
|
|
241
|
+
Lower than operator.
|
|
242
|
+
|
|
243
|
+
Args:
|
|
244
|
+
other (int or Bip32Depth object): Other value to compare
|
|
245
|
+
|
|
246
|
+
Returns:
|
|
247
|
+
bool: True if lower false otherwise
|
|
248
|
+
"""
|
|
249
|
+
if isinstance(other, int):
|
|
250
|
+
return self.m_depth < other
|
|
251
|
+
return self.m_depth < other.m_depth
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
class Bip32KeyIndex:
|
|
255
|
+
"""
|
|
256
|
+
BIP32 key index class.
|
|
257
|
+
It represents a BIP32 key index.
|
|
258
|
+
"""
|
|
259
|
+
|
|
260
|
+
m_idx: int
|
|
261
|
+
|
|
262
|
+
@staticmethod
|
|
263
|
+
def HardenIndex(index: int) -> int:
|
|
264
|
+
"""
|
|
265
|
+
Harden the specified index and return it.
|
|
266
|
+
|
|
267
|
+
Args:
|
|
268
|
+
index (int): Index
|
|
269
|
+
|
|
270
|
+
Returns:
|
|
271
|
+
int: Hardened index
|
|
272
|
+
"""
|
|
273
|
+
return BitUtils.SetBit(index, Bip32KeyDataConst.KEY_INDEX_HARDENED_BIT_NUM)
|
|
274
|
+
|
|
275
|
+
@staticmethod
|
|
276
|
+
def UnhardenIndex(index: int) -> int:
|
|
277
|
+
"""
|
|
278
|
+
Unharden the specified index and return it.
|
|
279
|
+
|
|
280
|
+
Args:
|
|
281
|
+
index (int): Index
|
|
282
|
+
|
|
283
|
+
Returns:
|
|
284
|
+
int: Unhardened index
|
|
285
|
+
"""
|
|
286
|
+
return BitUtils.ResetBit(index, Bip32KeyDataConst.KEY_INDEX_HARDENED_BIT_NUM)
|
|
287
|
+
|
|
288
|
+
@staticmethod
|
|
289
|
+
def IsHardenedIndex(index: int) -> bool:
|
|
290
|
+
"""
|
|
291
|
+
Get if the specified index is hardened.
|
|
292
|
+
|
|
293
|
+
Args:
|
|
294
|
+
index (int): Index
|
|
295
|
+
|
|
296
|
+
Returns:
|
|
297
|
+
bool: True if hardened, false otherwise
|
|
298
|
+
"""
|
|
299
|
+
return BitUtils.IsBitSet(index, Bip32KeyDataConst.KEY_INDEX_HARDENED_BIT_NUM)
|
|
300
|
+
|
|
301
|
+
@classmethod
|
|
302
|
+
def FromBytes(cls,
|
|
303
|
+
index_bytes: bytes) -> Bip32KeyIndex:
|
|
304
|
+
"""
|
|
305
|
+
Construct class from bytes.
|
|
306
|
+
|
|
307
|
+
Args:
|
|
308
|
+
index_bytes (bytes): Key index bytes
|
|
309
|
+
|
|
310
|
+
Returns:
|
|
311
|
+
Bip32KeyIndex object: Bip32KeyIndex object
|
|
312
|
+
|
|
313
|
+
Raises:
|
|
314
|
+
ValueError: If the index is not valid
|
|
315
|
+
"""
|
|
316
|
+
return cls(BytesUtils.ToInteger(index_bytes))
|
|
317
|
+
|
|
318
|
+
def __init__(self,
|
|
319
|
+
idx: int) -> None:
|
|
320
|
+
"""
|
|
321
|
+
Construct class.
|
|
322
|
+
|
|
323
|
+
Args:
|
|
324
|
+
idx (int): Key index
|
|
325
|
+
|
|
326
|
+
Raises:
|
|
327
|
+
ValueError: If the index value is not valid
|
|
328
|
+
"""
|
|
329
|
+
if idx < 0 or idx > Bip32KeyDataConst.KEY_INDEX_MAX_VAL:
|
|
330
|
+
raise ValueError(f"Invalid key index ({idx})")
|
|
331
|
+
self.m_idx = idx
|
|
332
|
+
|
|
333
|
+
@staticmethod
|
|
334
|
+
def FixedLength() -> int:
|
|
335
|
+
"""
|
|
336
|
+
Get the fixed length in bytes.
|
|
337
|
+
|
|
338
|
+
Returns:
|
|
339
|
+
int: Length in bytes
|
|
340
|
+
"""
|
|
341
|
+
return Bip32KeyDataConst.KEY_INDEX_BYTE_LEN
|
|
342
|
+
|
|
343
|
+
def Harden(self) -> Bip32KeyIndex:
|
|
344
|
+
"""
|
|
345
|
+
Get a new Bip32KeyIndex object with the current key index hardened.
|
|
346
|
+
|
|
347
|
+
Returns:
|
|
348
|
+
Bip32KeyIndex object: Bip32KeyIndex object
|
|
349
|
+
"""
|
|
350
|
+
return Bip32KeyIndex(self.HardenIndex(self.m_idx))
|
|
351
|
+
|
|
352
|
+
def Unharden(self) -> Bip32KeyIndex:
|
|
353
|
+
"""
|
|
354
|
+
Get a new Bip32KeyIndex object with the current key index unhardened.
|
|
355
|
+
|
|
356
|
+
Returns:
|
|
357
|
+
Bip32KeyIndex object: Bip32KeyIndex object
|
|
358
|
+
"""
|
|
359
|
+
return Bip32KeyIndex(self.UnhardenIndex(self.m_idx))
|
|
360
|
+
|
|
361
|
+
def IsHardened(self) -> bool:
|
|
362
|
+
"""
|
|
363
|
+
Get if the key index is hardened.
|
|
364
|
+
|
|
365
|
+
Returns:
|
|
366
|
+
bool: True if hardened, false otherwise
|
|
367
|
+
"""
|
|
368
|
+
return self.IsHardenedIndex(self.m_idx)
|
|
369
|
+
|
|
370
|
+
def ToBytes(self,
|
|
371
|
+
endianness: Literal["little", "big"] = "big") -> bytes:
|
|
372
|
+
"""
|
|
373
|
+
Get the key index as bytes.
|
|
374
|
+
|
|
375
|
+
Args:
|
|
376
|
+
endianness ("big" or "little", optional): Endianness (default: big)
|
|
377
|
+
|
|
378
|
+
Returns:
|
|
379
|
+
bytes: Key bytes
|
|
380
|
+
"""
|
|
381
|
+
return IntegerUtils.ToBytes(self.m_idx,
|
|
382
|
+
bytes_num=self.FixedLength(),
|
|
383
|
+
endianness=endianness)
|
|
384
|
+
|
|
385
|
+
def ToInt(self) -> int:
|
|
386
|
+
"""
|
|
387
|
+
Get the key index as integer.
|
|
388
|
+
|
|
389
|
+
Returns:
|
|
390
|
+
int: Key index
|
|
391
|
+
"""
|
|
392
|
+
return int(self.m_idx)
|
|
393
|
+
|
|
394
|
+
def __int__(self) -> int:
|
|
395
|
+
"""
|
|
396
|
+
Get the key index as integer.
|
|
397
|
+
|
|
398
|
+
Returns:
|
|
399
|
+
int: Key index
|
|
400
|
+
"""
|
|
401
|
+
return self.ToInt()
|
|
402
|
+
|
|
403
|
+
def __bytes__(self) -> bytes:
|
|
404
|
+
"""
|
|
405
|
+
Get the key index as bytes.
|
|
406
|
+
|
|
407
|
+
Returns:
|
|
408
|
+
bytes: Key bytes
|
|
409
|
+
"""
|
|
410
|
+
return self.ToBytes()
|
|
411
|
+
|
|
412
|
+
def __eq__(self,
|
|
413
|
+
other: object) -> bool:
|
|
414
|
+
"""
|
|
415
|
+
Equality operator.
|
|
416
|
+
|
|
417
|
+
Args:
|
|
418
|
+
other (int or Bip32KeyIndex object): Other value to compare
|
|
419
|
+
|
|
420
|
+
Returns:
|
|
421
|
+
bool: True if equal false otherwise
|
|
422
|
+
|
|
423
|
+
Raises:
|
|
424
|
+
TypeError: If the object is not of the correct type
|
|
425
|
+
"""
|
|
426
|
+
if not isinstance(other, (int, Bip32KeyIndex)):
|
|
427
|
+
raise TypeError(f"Invalid type for checking equality ({type(other)})")
|
|
428
|
+
|
|
429
|
+
if isinstance(other, int):
|
|
430
|
+
return self.m_idx == other
|
|
431
|
+
return self.m_idx == other.m_idx
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
class Bip32KeyData:
|
|
435
|
+
"""
|
|
436
|
+
BIP32 key data class.
|
|
437
|
+
It contains all additional data related to a BIP32 key (e.g. depth, chain code, etc...).
|
|
438
|
+
"""
|
|
439
|
+
|
|
440
|
+
m_depth: Bip32Depth
|
|
441
|
+
m_index: Bip32KeyIndex
|
|
442
|
+
m_chain_code: Bip32ChainCode
|
|
443
|
+
m_parent_fprint: Bip32FingerPrint
|
|
444
|
+
|
|
445
|
+
def __init__(self,
|
|
446
|
+
depth: Union[int, Bip32Depth] = Bip32Depth(0),
|
|
447
|
+
index: Union[int, Bip32KeyIndex] = Bip32KeyIndex(0),
|
|
448
|
+
chain_code: Union[bytes, Bip32ChainCode] = Bip32ChainCode(),
|
|
449
|
+
parent_fprint: Union[bytes, Bip32FingerPrint] = Bip32FingerPrint()) -> None:
|
|
450
|
+
"""
|
|
451
|
+
Construct class.
|
|
452
|
+
|
|
453
|
+
Args:
|
|
454
|
+
depth (Bip32Depth object) : Key depth
|
|
455
|
+
index (Bip32KeyIndex object) : Key index
|
|
456
|
+
chain_code (Bip32ChainCode object) : Key chain code
|
|
457
|
+
parent_fprint (Bip32FingerPrint object) : Key parent fingerprint
|
|
458
|
+
"""
|
|
459
|
+
self.m_depth = depth if isinstance(depth, Bip32Depth) else Bip32Depth(depth)
|
|
460
|
+
self.m_index = index if isinstance(index, Bip32KeyIndex) else Bip32KeyIndex(index)
|
|
461
|
+
self.m_chain_code = chain_code if isinstance(chain_code, Bip32ChainCode) else Bip32ChainCode(chain_code)
|
|
462
|
+
self.m_parent_fprint = (parent_fprint
|
|
463
|
+
if isinstance(parent_fprint, Bip32FingerPrint)
|
|
464
|
+
else Bip32FingerPrint(parent_fprint))
|
|
465
|
+
|
|
466
|
+
def Depth(self) -> Bip32Depth:
|
|
467
|
+
"""
|
|
468
|
+
Get current depth.
|
|
469
|
+
|
|
470
|
+
Returns:
|
|
471
|
+
Bip32Depth object: Current depth
|
|
472
|
+
"""
|
|
473
|
+
return self.m_depth
|
|
474
|
+
|
|
475
|
+
def Index(self) -> Bip32KeyIndex:
|
|
476
|
+
"""
|
|
477
|
+
Get current index.
|
|
478
|
+
|
|
479
|
+
Returns:
|
|
480
|
+
Bip32KeyIndex object: Current index
|
|
481
|
+
"""
|
|
482
|
+
return self.m_index
|
|
483
|
+
|
|
484
|
+
def ChainCode(self) -> Bip32ChainCode:
|
|
485
|
+
"""
|
|
486
|
+
Get current chain code.
|
|
487
|
+
|
|
488
|
+
Returns:
|
|
489
|
+
Bip32ChainCode object: Chain code
|
|
490
|
+
"""
|
|
491
|
+
return self.m_chain_code
|
|
492
|
+
|
|
493
|
+
def ParentFingerPrint(self) -> Bip32FingerPrint:
|
|
494
|
+
"""
|
|
495
|
+
Get parent fingerprint.
|
|
496
|
+
|
|
497
|
+
Returns:
|
|
498
|
+
Bip32FingerPrint object: Parent fingerprint
|
|
499
|
+
"""
|
|
500
|
+
return self.m_parent_fprint
|
|
@@ -0,0 +1,83 @@
|
|
|
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 net version class."""
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class Bip32KeyNetVersionsConst:
|
|
25
|
+
"""Class container for BIP32 key net versions constants."""
|
|
26
|
+
|
|
27
|
+
# Key net version length in bytes
|
|
28
|
+
KEY_NET_VERSION_BYTE_LEN: int = 4
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class Bip32KeyNetVersions:
|
|
32
|
+
"""
|
|
33
|
+
BIP32 key net versions class.
|
|
34
|
+
It represents a BIP32 key net versions.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
m_pub_net_ver: bytes
|
|
38
|
+
m_priv_net_ver: bytes
|
|
39
|
+
|
|
40
|
+
def __init__(self,
|
|
41
|
+
pub_net_ver: bytes,
|
|
42
|
+
priv_net_ver: bytes) -> None:
|
|
43
|
+
"""
|
|
44
|
+
Construct class.
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
pub_net_ver (bytes) : Public net version
|
|
48
|
+
priv_net_ver (bytes): Private net version
|
|
49
|
+
"""
|
|
50
|
+
if (len(pub_net_ver) != self.Length()
|
|
51
|
+
or len(priv_net_ver) != self.Length()):
|
|
52
|
+
raise ValueError("Invalid key net version length")
|
|
53
|
+
|
|
54
|
+
self.m_pub_net_ver = pub_net_ver
|
|
55
|
+
self.m_priv_net_ver = priv_net_ver
|
|
56
|
+
|
|
57
|
+
@staticmethod
|
|
58
|
+
def Length() -> int:
|
|
59
|
+
"""
|
|
60
|
+
Get the key net version length.
|
|
61
|
+
|
|
62
|
+
Returns:
|
|
63
|
+
int: Key net version length
|
|
64
|
+
"""
|
|
65
|
+
return Bip32KeyNetVersionsConst.KEY_NET_VERSION_BYTE_LEN
|
|
66
|
+
|
|
67
|
+
def Public(self) -> bytes:
|
|
68
|
+
"""
|
|
69
|
+
Get public net version.
|
|
70
|
+
|
|
71
|
+
Returns:
|
|
72
|
+
bytes: Public net version
|
|
73
|
+
"""
|
|
74
|
+
return self.m_pub_net_ver
|
|
75
|
+
|
|
76
|
+
def Private(self) -> bytes:
|
|
77
|
+
"""
|
|
78
|
+
Get private net version.
|
|
79
|
+
|
|
80
|
+
Returns:
|
|
81
|
+
bytes: Private net version
|
|
82
|
+
"""
|
|
83
|
+
return self.m_priv_net_ver
|