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.

Files changed (197) hide show
  1. coinex/ccxt/__init__.py +1 -1
  2. coinex/ccxt/async_support/__init__.py +1 -1
  3. coinex/ccxt/async_support/base/exchange.py +139 -10
  4. coinex/ccxt/async_support/base/throttler.py +1 -1
  5. coinex/ccxt/async_support/base/ws/cache.py +1 -0
  6. coinex/ccxt/async_support/base/ws/client.py +26 -4
  7. coinex/ccxt/async_support/coinex.py +2 -2
  8. coinex/ccxt/base/exchange.py +587 -91
  9. coinex/ccxt/base/types.py +11 -2
  10. coinex/ccxt/coinex.py +2 -2
  11. coinex/ccxt/pro/__init__.py +1 -1
  12. coinex/ccxt/pro/coinex.py +10 -7
  13. coinex/ccxt/static_dependencies/bip/__init__.py +6 -0
  14. coinex/ccxt/static_dependencies/bip/addr/P2PKH_addr.py +205 -0
  15. coinex/ccxt/static_dependencies/bip/addr/__init__.py +5 -0
  16. coinex/ccxt/static_dependencies/bip/addr/addr_dec_utils.py +125 -0
  17. coinex/ccxt/static_dependencies/bip/addr/addr_key_validator.py +162 -0
  18. coinex/ccxt/static_dependencies/bip/addr/iaddr_decoder.py +48 -0
  19. coinex/ccxt/static_dependencies/bip/addr/iaddr_encoder.py +50 -0
  20. coinex/ccxt/static_dependencies/bip/base58/__init__.py +3 -0
  21. coinex/ccxt/static_dependencies/bip/base58/base58.py +207 -0
  22. coinex/ccxt/static_dependencies/bip/base58/base58_ex.py +25 -0
  23. coinex/ccxt/static_dependencies/bip/base58/base58_xmr.py +155 -0
  24. coinex/ccxt/static_dependencies/bip/bech32/__init__.py +4 -0
  25. coinex/ccxt/static_dependencies/bip/bech32/bch_bech32.py +220 -0
  26. coinex/ccxt/static_dependencies/bip/bech32/bech32.py +235 -0
  27. coinex/ccxt/static_dependencies/bip/bech32/bech32_base.py +246 -0
  28. coinex/ccxt/static_dependencies/bip/bech32/bech32_ex.py +25 -0
  29. coinex/ccxt/static_dependencies/bip/bech32/segwit_bech32.py +173 -0
  30. coinex/ccxt/static_dependencies/bip/bip32/__init__.py +14 -0
  31. coinex/ccxt/static_dependencies/bip/bip32/base/__init__.py +3 -0
  32. coinex/ccxt/static_dependencies/bip/bip32/base/bip32_base.py +581 -0
  33. coinex/ccxt/static_dependencies/bip/bip32/base/ibip32_key_derivator.py +83 -0
  34. coinex/ccxt/static_dependencies/bip/bip32/base/ibip32_mst_key_generator.py +47 -0
  35. coinex/ccxt/static_dependencies/bip/bip32/bip32_const.py +35 -0
  36. coinex/ccxt/static_dependencies/bip/bip32/bip32_ex.py +29 -0
  37. coinex/ccxt/static_dependencies/bip/bip32/bip32_key_data.py +500 -0
  38. coinex/ccxt/static_dependencies/bip/bip32/bip32_key_net_ver.py +83 -0
  39. coinex/ccxt/static_dependencies/bip/bip32/bip32_key_ser.py +294 -0
  40. coinex/ccxt/static_dependencies/bip/bip32/bip32_keys.py +457 -0
  41. coinex/ccxt/static_dependencies/bip/bip32/bip32_path.py +247 -0
  42. coinex/ccxt/static_dependencies/bip/bip32/bip32_utils.py +72 -0
  43. coinex/ccxt/static_dependencies/bip/bip32/kholaw/__init__.py +4 -0
  44. coinex/ccxt/static_dependencies/bip/bip32/kholaw/bip32_kholaw_ed25519.py +82 -0
  45. coinex/ccxt/static_dependencies/bip/bip32/kholaw/bip32_kholaw_ed25519_key_derivator.py +118 -0
  46. coinex/ccxt/static_dependencies/bip/bip32/kholaw/bip32_kholaw_key_derivator_base.py +204 -0
  47. coinex/ccxt/static_dependencies/bip/bip32/kholaw/bip32_kholaw_mst_key_generator.py +119 -0
  48. coinex/ccxt/static_dependencies/bip/bip32/slip10/__init__.py +1 -0
  49. coinex/ccxt/static_dependencies/bip/bip32/slip10/bip32_slip10_key_derivator.py +200 -0
  50. coinex/ccxt/static_dependencies/bip/bip32/slip10/bip32_slip10_mst_key_generator.py +168 -0
  51. coinex/ccxt/static_dependencies/bip/bip32/slip10/bip32_slip10_secp256k1.py +82 -0
  52. coinex/ccxt/static_dependencies/bip/bip44/__init__.py +1 -0
  53. coinex/ccxt/static_dependencies/bip/bip44/bip44.py +265 -0
  54. coinex/ccxt/static_dependencies/bip/bip44_base/__init__.py +3 -0
  55. coinex/ccxt/static_dependencies/bip/bip44_base/bip44_base.py +624 -0
  56. coinex/ccxt/static_dependencies/bip/bip44_base/bip44_base_ex.py +25 -0
  57. coinex/ccxt/static_dependencies/bip/bip44_base/bip44_keys.py +225 -0
  58. coinex/ccxt/static_dependencies/bip/coin_conf/__init__.py +2 -0
  59. coinex/ccxt/static_dependencies/bip/coin_conf/coin_conf.py +68 -0
  60. coinex/ccxt/static_dependencies/bip/coin_conf/coins_conf.py +890 -0
  61. coinex/ccxt/static_dependencies/bip/conf/__init__.py +0 -0
  62. coinex/ccxt/static_dependencies/bip/conf/bip44/__init__.py +3 -0
  63. coinex/ccxt/static_dependencies/bip/conf/bip44/bip44_coins.py +126 -0
  64. coinex/ccxt/static_dependencies/bip/conf/bip44/bip44_conf.py +1360 -0
  65. coinex/ccxt/static_dependencies/bip/conf/bip44/bip44_conf_getter.py +153 -0
  66. coinex/ccxt/static_dependencies/bip/conf/bip49/__init__.py +3 -0
  67. coinex/ccxt/static_dependencies/bip/conf/bip49/bip49_coins.py +53 -0
  68. coinex/ccxt/static_dependencies/bip/conf/bip49/bip49_conf.py +366 -0
  69. coinex/ccxt/static_dependencies/bip/conf/bip49/bip49_conf_getter.py +80 -0
  70. coinex/ccxt/static_dependencies/bip/conf/bip84/__init__.py +3 -0
  71. coinex/ccxt/static_dependencies/bip/conf/bip84/bip84_coins.py +39 -0
  72. coinex/ccxt/static_dependencies/bip/conf/bip84/bip84_conf.py +113 -0
  73. coinex/ccxt/static_dependencies/bip/conf/bip84/bip84_conf_getter.py +66 -0
  74. coinex/ccxt/static_dependencies/bip/conf/bip86/__init__.py +3 -0
  75. coinex/ccxt/static_dependencies/bip/conf/bip86/bip86_coins.py +37 -0
  76. coinex/ccxt/static_dependencies/bip/conf/bip86/bip86_conf.py +83 -0
  77. coinex/ccxt/static_dependencies/bip/conf/bip86/bip86_conf_getter.py +64 -0
  78. coinex/ccxt/static_dependencies/bip/conf/common/__init__.py +8 -0
  79. coinex/ccxt/static_dependencies/bip/conf/common/atom_addr.py +104 -0
  80. coinex/ccxt/static_dependencies/bip/conf/common/bip_bitcoin_cash_conf.py +106 -0
  81. coinex/ccxt/static_dependencies/bip/conf/common/bip_coin_conf.py +217 -0
  82. coinex/ccxt/static_dependencies/bip/conf/common/bip_coins.py +28 -0
  83. coinex/ccxt/static_dependencies/bip/conf/common/bip_conf_const.py +30 -0
  84. coinex/ccxt/static_dependencies/bip/conf/common/bip_litecoin_conf.py +121 -0
  85. coinex/ccxt/static_dependencies/bip/ecc/__init__.py +42 -0
  86. coinex/ccxt/static_dependencies/bip/ecc/common/__init__.py +0 -0
  87. coinex/ccxt/static_dependencies/bip/ecc/common/dummy_point.py +219 -0
  88. coinex/ccxt/static_dependencies/bip/ecc/common/ikeys.py +263 -0
  89. coinex/ccxt/static_dependencies/bip/ecc/common/ipoint.py +190 -0
  90. coinex/ccxt/static_dependencies/bip/ecc/conf.py +28 -0
  91. coinex/ccxt/static_dependencies/bip/ecc/curve/__init__.py +0 -0
  92. coinex/ccxt/static_dependencies/bip/ecc/curve/elliptic_curve.py +121 -0
  93. coinex/ccxt/static_dependencies/bip/ecc/curve/elliptic_curve_getter.py +74 -0
  94. coinex/ccxt/static_dependencies/bip/ecc/curve/elliptic_curve_types.py +37 -0
  95. coinex/ccxt/static_dependencies/bip/ecc/ecdsa/__init__.py +0 -0
  96. coinex/ccxt/static_dependencies/bip/ecc/ecdsa/ecdsa_keys.py +36 -0
  97. coinex/ccxt/static_dependencies/bip/ecc/secp256k1/__init__.py +0 -0
  98. coinex/ccxt/static_dependencies/bip/ecc/secp256k1/secp256k1.py +36 -0
  99. coinex/ccxt/static_dependencies/bip/ecc/secp256k1/secp256k1_const.py +59 -0
  100. coinex/ccxt/static_dependencies/bip/ecc/secp256k1/secp256k1_keys_ecdsa.py +248 -0
  101. coinex/ccxt/static_dependencies/bip/ecc/secp256k1/secp256k1_point_ecdsa.py +234 -0
  102. coinex/ccxt/static_dependencies/bip/slip/__init__.py +0 -0
  103. coinex/ccxt/static_dependencies/bip/slip/slip173/__init__.py +1 -0
  104. coinex/ccxt/static_dependencies/bip/slip/slip173/slip173.py +60 -0
  105. coinex/ccxt/static_dependencies/bip/slip/slip32/__init__.py +4 -0
  106. coinex/ccxt/static_dependencies/bip/slip/slip32/slip32.py +322 -0
  107. coinex/ccxt/static_dependencies/bip/slip/slip32/slip32_key_net_ver.py +62 -0
  108. coinex/ccxt/static_dependencies/bip/slip/slip44/__init__.py +1 -0
  109. coinex/ccxt/static_dependencies/bip/slip/slip44/slip44.py +81 -0
  110. coinex/ccxt/static_dependencies/bip/utils/__init__.py +0 -0
  111. coinex/ccxt/static_dependencies/bip/utils/conf/__init__.py +1 -0
  112. coinex/ccxt/static_dependencies/bip/utils/conf/coin_names.py +59 -0
  113. coinex/ccxt/static_dependencies/bip/utils/crypto/__init__.py +10 -0
  114. coinex/ccxt/static_dependencies/bip/utils/crypto/aes_ecb.py +152 -0
  115. coinex/ccxt/static_dependencies/bip/utils/crypto/blake2.py +191 -0
  116. coinex/ccxt/static_dependencies/bip/utils/crypto/chacha20_poly1305.py +101 -0
  117. coinex/ccxt/static_dependencies/bip/utils/crypto/hash160.py +57 -0
  118. coinex/ccxt/static_dependencies/bip/utils/crypto/hmac.py +118 -0
  119. coinex/ccxt/static_dependencies/bip/utils/crypto/pbkdf2.py +66 -0
  120. coinex/ccxt/static_dependencies/bip/utils/crypto/ripemd.py +58 -0
  121. coinex/ccxt/static_dependencies/bip/utils/crypto/scrypt.py +66 -0
  122. coinex/ccxt/static_dependencies/bip/utils/crypto/sha2.py +182 -0
  123. coinex/ccxt/static_dependencies/bip/utils/crypto/sha3.py +99 -0
  124. coinex/ccxt/static_dependencies/bip/utils/misc/__init__.py +7 -0
  125. coinex/ccxt/static_dependencies/bip/utils/misc/algo.py +108 -0
  126. coinex/ccxt/static_dependencies/bip/utils/misc/base32.py +151 -0
  127. coinex/ccxt/static_dependencies/bip/utils/misc/bit.py +115 -0
  128. coinex/ccxt/static_dependencies/bip/utils/misc/bytes.py +200 -0
  129. coinex/ccxt/static_dependencies/bip/utils/misc/data_bytes.py +181 -0
  130. coinex/ccxt/static_dependencies/bip/utils/misc/integer.py +97 -0
  131. coinex/ccxt/static_dependencies/bip/utils/misc/string.py +54 -0
  132. coinex/ccxt/static_dependencies/bip/utils/typing/__init__.py +1 -0
  133. coinex/ccxt/static_dependencies/bip/utils/typing/literal.py +27 -0
  134. coinex/ccxt/static_dependencies/bip/wif/__init__.py +1 -0
  135. coinex/ccxt/static_dependencies/bip/wif/wif.py +144 -0
  136. coinex/ccxt/static_dependencies/dydx_v4_client/amino/amino_pb2.py +31 -0
  137. coinex/ccxt/static_dependencies/dydx_v4_client/cosmos/base/v1beta1/coin_pb2.py +47 -0
  138. coinex/ccxt/static_dependencies/dydx_v4_client/cosmos/crypto/multisig/keys_pb2.py +33 -0
  139. coinex/ccxt/static_dependencies/dydx_v4_client/cosmos/crypto/multisig/v1beta1/multisig_pb2.py +33 -0
  140. coinex/ccxt/static_dependencies/dydx_v4_client/cosmos/crypto/secp256k1/keys_pb2.py +34 -0
  141. coinex/ccxt/static_dependencies/dydx_v4_client/cosmos/msg/v1/msg_pb2.py +27 -0
  142. coinex/ccxt/static_dependencies/dydx_v4_client/cosmos/tx/signing/v1beta1/signing_pb2.py +38 -0
  143. coinex/ccxt/static_dependencies/dydx_v4_client/cosmos/tx/v1beta1/tx_pb2.py +75 -0
  144. coinex/ccxt/static_dependencies/dydx_v4_client/cosmos_proto/cosmos_pb2.py +36 -0
  145. coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/accountplus/accountplus_pb2.py +31 -0
  146. coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/accountplus/genesis_pb2.py +40 -0
  147. coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/accountplus/models_pb2.py +26 -0
  148. coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/accountplus/params_pb2.py +29 -0
  149. coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/accountplus/query_pb2.py +57 -0
  150. coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/accountplus/tx_pb2.py +51 -0
  151. coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/block_rate_limit_config_pb2.py +37 -0
  152. coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/clob_pair_pb2.py +41 -0
  153. coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/equity_tier_limit_config_pb2.py +35 -0
  154. coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/finalize_block_pb2.py +27 -0
  155. coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/liquidations_config_pb2.py +39 -0
  156. coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/liquidations_pb2.py +38 -0
  157. coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/matches_pb2.py +55 -0
  158. coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/mev_pb2.py +49 -0
  159. coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/operation_pb2.py +32 -0
  160. coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/order_pb2.py +86 -0
  161. coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/order_removals_pb2.py +32 -0
  162. coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/process_proposer_matches_events_pb2.py +42 -0
  163. coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/query_pb2.py +124 -0
  164. coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/streaming_pb2.py +29 -0
  165. coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/tx_pb2.py +117 -0
  166. coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/sending/genesis_pb2.py +26 -0
  167. coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/sending/query_pb2.py +26 -0
  168. coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/sending/transfer_pb2.py +61 -0
  169. coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/sending/tx_pb2.py +37 -0
  170. coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/subaccounts/asset_position_pb2.py +29 -0
  171. coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/subaccounts/genesis_pb2.py +30 -0
  172. coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/subaccounts/perpetual_position_pb2.py +33 -0
  173. coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/subaccounts/query_pb2.py +63 -0
  174. coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/subaccounts/streaming_pb2.py +31 -0
  175. coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/subaccounts/subaccount_pb2.py +33 -0
  176. coinex/ccxt/static_dependencies/dydx_v4_client/gogoproto/gogo_pb2.py +102 -0
  177. coinex/ccxt/static_dependencies/dydx_v4_client/registry.py +38 -0
  178. coinex/ccxt/static_dependencies/ecdsa/ellipticcurve.py +842 -0
  179. coinex/ccxt/static_dependencies/ecdsa/keys.py +15 -4
  180. coinex/ccxt/static_dependencies/mnemonic/__init__.py +4 -0
  181. coinex/ccxt/static_dependencies/mnemonic/mnemonic.py +282 -0
  182. coinex/ccxt/static_dependencies/mnemonic/py.typed +1 -0
  183. coinex/ccxt/static_dependencies/mnemonic/wordlist/chinese_simplified.txt +2048 -0
  184. coinex/ccxt/static_dependencies/mnemonic/wordlist/chinese_traditional.txt +2048 -0
  185. coinex/ccxt/static_dependencies/mnemonic/wordlist/czech.txt +2048 -0
  186. coinex/ccxt/static_dependencies/mnemonic/wordlist/english.txt +2048 -0
  187. coinex/ccxt/static_dependencies/mnemonic/wordlist/french.txt +2048 -0
  188. coinex/ccxt/static_dependencies/mnemonic/wordlist/italian.txt +2048 -0
  189. coinex/ccxt/static_dependencies/mnemonic/wordlist/japanese.txt +2048 -0
  190. coinex/ccxt/static_dependencies/mnemonic/wordlist/korean.txt +2048 -0
  191. coinex/ccxt/static_dependencies/mnemonic/wordlist/portuguese.txt +2048 -0
  192. coinex/ccxt/static_dependencies/mnemonic/wordlist/russian.txt +2048 -0
  193. coinex/ccxt/static_dependencies/mnemonic/wordlist/spanish.txt +2048 -0
  194. coinex/ccxt/static_dependencies/mnemonic/wordlist/turkish.txt +2048 -0
  195. {coinex_api-0.0.89.dist-info → coinex_api-0.0.110.dist-info}/METADATA +3 -3
  196. {coinex_api-0.0.89.dist-info → coinex_api-0.0.110.dist-info}/RECORD +197 -17
  197. {coinex_api-0.0.89.dist-info → coinex_api-0.0.110.dist-info}/WHEEL +1 -1
@@ -0,0 +1,624 @@
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
+
22
+ """Module with BIP44 base class."""
23
+
24
+ # Imports
25
+ from __future__ import annotations
26
+
27
+ from abc import ABC, abstractmethod
28
+ from enum import IntEnum, unique
29
+ from functools import lru_cache
30
+ from typing import Union
31
+
32
+ from ..bip32 import Bip32Base, Bip32KeyData, Bip32KeyIndex
33
+ from ..bip44_base.bip44_base_ex import Bip44DepthError
34
+ from ..bip44_base.bip44_keys import Bip44PrivateKey, Bip44PublicKey
35
+ from ..conf.common import BipCoinConf, BipCoins
36
+ from ..ecc import IPrivateKey, IPublicKey
37
+
38
+
39
+ @unique
40
+ class Bip44Changes(IntEnum):
41
+ """Enumerative for BIP44 changes."""
42
+
43
+ CHAIN_EXT = 0
44
+ CHAIN_INT = 1
45
+
46
+
47
+ @unique
48
+ class Bip44Levels(IntEnum):
49
+ """Enumerative for BIP44 levels."""
50
+
51
+ MASTER = 0
52
+ PURPOSE = 1
53
+ COIN = 2
54
+ ACCOUNT = 3
55
+ CHANGE = 4
56
+ ADDRESS_INDEX = 5
57
+
58
+
59
+ class Bip44Base(ABC):
60
+ """
61
+ BIP44 base class.
62
+ It allows coin, account, chain and address keys generation in according to BIP44 or its extensions.
63
+ The class is meant to be derived by classes implementing BIP44 or its extensions.
64
+ """
65
+
66
+ m_bip32_obj: Bip32Base
67
+ m_coin_conf: BipCoinConf
68
+
69
+ #
70
+ # Class methods for construction
71
+ #
72
+
73
+ @classmethod
74
+ def _FromSeed(cls,
75
+ seed_bytes: bytes,
76
+ coin_conf: BipCoinConf) -> Bip44Base:
77
+ """
78
+ Create a Bip44Base object from the specified seed (e.g. BIP39 seed).
79
+
80
+ Args:
81
+ seed_bytes (bytes) : Seed bytes
82
+ coin_conf (BipCoinConf): BipCoinConf object
83
+
84
+ Returns:
85
+ Bip44Base object: Bip44Base object
86
+
87
+ Raises:
88
+ ValueError: If the seed is too short
89
+ Bip32KeyError: If the seed is not suitable for master key generation
90
+ """
91
+ bip32_cls = coin_conf.Bip32Class()
92
+ return cls(bip32_cls.FromSeed(seed_bytes,
93
+ coin_conf.KeyNetVersions()),
94
+ coin_conf)
95
+
96
+ @classmethod
97
+ def _FromExtendedKey(cls,
98
+ ex_key_str: str,
99
+ coin_conf: BipCoinConf) -> Bip44Base:
100
+ """
101
+ Create a Bip44Base object from the specified extended key.
102
+
103
+ Args:
104
+ ex_key_str (str) : Extended key string
105
+ coin_conf (BipCoinConf): BipCoinConf object
106
+
107
+ Returns:
108
+ Bip44Base object: Bip44Base object
109
+
110
+ Raises:
111
+ Bip32KeyError: If the extended key is not valid
112
+ """
113
+ bip32_cls = coin_conf.Bip32Class()
114
+ return cls(bip32_cls.FromExtendedKey(ex_key_str, coin_conf.KeyNetVersions()),
115
+ coin_conf)
116
+
117
+ # @classmethod
118
+ # def _FromPrivateKey(cls,
119
+ # priv_key: Union[bytes, IPrivateKey],
120
+ # coin_conf: BipCoinConf,
121
+ # key_data: Bip32KeyData) -> Bip44Base:
122
+ # """
123
+ # Create a Bip44Base object from the specified private key and derivation data.
124
+ # If only the private key bytes are specified, the key will be considered a master key with
125
+ # the chain code set to zero, since there is no way to recover the key derivation data.
126
+
127
+ # Args:
128
+ # priv_key (bytes or IPrivateKey): Private key
129
+ # coin_conf (BipCoinConf) : BipCoinConf object
130
+ # key_data (Bip32KeyData object) : Key data
131
+
132
+ # Returns:
133
+ # Bip44Base object: Bip44Base object
134
+
135
+ # Raises:
136
+ # Bip32KeyError: If the key is not valid
137
+ # """
138
+ # bip32_cls = coin_conf.Bip32Class()
139
+ # return cls(bip32_cls.FromPrivateKey(priv_key,
140
+ # key_data,
141
+ # coin_conf.KeyNetVersions()),
142
+ # coin_conf)
143
+
144
+ # @classmethod
145
+ # def _FromPublicKey(cls,
146
+ # pub_key: Union[bytes, IPublicKey],
147
+ # coin_conf: BipCoinConf,
148
+ # key_data: Bip32KeyData) -> Bip44Base:
149
+ # """
150
+ # Create a Bip44Base object from the specified public key and derivation data.
151
+ # If only the public key bytes are specified, the key will be considered an account key with
152
+ # the chain code set to zero, since there is no way to recover the key derivation data.
153
+
154
+ # Args:
155
+ # pub_key (bytes or IPublicKey) : Public key
156
+ # coin_conf (BipCoinConf) : BipCoinConf object
157
+ # key_data (Bip32KeyData object) : Key data
158
+
159
+ # Returns:
160
+ # Bip44Base object: Bip44Base object
161
+
162
+ # Raises:
163
+ # Bip32KeyError: If the key is not valid
164
+ # """
165
+ # bip32_cls = coin_conf.Bip32Class()
166
+ # return cls(bip32_cls.FromPublicKey(pub_key,
167
+ # key_data,
168
+ # coin_conf.KeyNetVersions()),
169
+ # coin_conf)
170
+
171
+ #
172
+ # Public methods
173
+ #
174
+
175
+ def __init__(self,
176
+ bip32_obj: Bip32Base,
177
+ coin_conf: BipCoinConf) -> None:
178
+ """
179
+ Construct class.
180
+
181
+ Args:
182
+ bip32_obj (Bip32Base object): Bip32Base object
183
+ coin_conf (BipCoinConf) : BipCoinConf object
184
+
185
+ Returns:
186
+ Bip44DepthError: If the Bip32 object depth is not valid
187
+ """
188
+ depth = bip32_obj.Depth()
189
+
190
+ # If the Bip32 is public-only, the depth shall start from the account level because hardened derivation is
191
+ # used below it, which is not possible with public keys
192
+ if bip32_obj.IsPublicOnly():
193
+ if depth < Bip44Levels.ACCOUNT or depth > Bip44Levels.ADDRESS_INDEX:
194
+ raise Bip44DepthError(
195
+ f"Depth of the public-only Bip object ({depth}) is below account level or "
196
+ f"beyond address index level"
197
+ )
198
+ # If the Bip32 object is not public-only, any depth is fine as long as it is not greater
199
+ # than address index level
200
+ else:
201
+ if depth < 0 or depth > Bip44Levels.ADDRESS_INDEX:
202
+ raise Bip44DepthError(
203
+ f"Depth of the Bip object ({depth}) is invalid or beyond address index level"
204
+ )
205
+
206
+ # Finally, initialize class
207
+ self.m_bip32_obj = bip32_obj
208
+ self.m_coin_conf = coin_conf
209
+
210
+ @lru_cache()
211
+ def PublicKey(self) -> Bip44PublicKey:
212
+ """
213
+ Return the public key.
214
+
215
+ Returns:
216
+ Bip44PublicKey object: Bip44PublicKey object
217
+ """
218
+ return Bip44PublicKey(self.m_bip32_obj.PublicKey(),
219
+ self.m_coin_conf)
220
+
221
+ @lru_cache()
222
+ def PrivateKey(self) -> Bip44PrivateKey:
223
+ """
224
+ Return the private key.
225
+
226
+ Returns:
227
+ Bip44PrivateKey object: Bip44PrivateKey object
228
+
229
+ Raises:
230
+ Bip32KeyError: If the Bip32 object is public-only
231
+ """
232
+ return Bip44PrivateKey(self.m_bip32_obj.PrivateKey(),
233
+ self.m_coin_conf)
234
+
235
+ def Bip32Object(self) -> Bip32Base:
236
+ """
237
+ Return the BIP32 object.
238
+
239
+ Returns:
240
+ Bip32Base object: Bip32Base object
241
+ """
242
+ return self.m_bip32_obj
243
+
244
+ def CoinConf(self) -> BipCoinConf:
245
+ """
246
+ Get coin configuration.
247
+
248
+ Returns:
249
+ BipCoinConf object: BipCoinConf object
250
+ """
251
+ return self.m_coin_conf
252
+
253
+ def IsPublicOnly(self) -> bool:
254
+ """
255
+ Get if it's public-only.
256
+
257
+ Returns:
258
+ bool: True if public-only, false otherwise
259
+ """
260
+ return self.m_bip32_obj.IsPublicOnly()
261
+
262
+ def Level(self) -> Bip44Levels:
263
+ """
264
+ Return the current level.
265
+
266
+ Returns:
267
+ Bip44Levels: Current level
268
+ """
269
+ return Bip44Levels(self.m_bip32_obj.Depth().ToInt())
270
+
271
+ def IsLevel(self,
272
+ level: Bip44Levels) -> bool:
273
+ """
274
+ Return if the current level is the specified one.
275
+
276
+ Args:
277
+ level (Bip44Levels): Level to be checked
278
+
279
+ Returns:
280
+ bool: True if it's the specified level, false otherwise
281
+
282
+ Raises:
283
+ TypeError: If the level index is not a Bip44Levels enum
284
+ """
285
+ if not isinstance(level, Bip44Levels):
286
+ raise TypeError("Level is not an enumerative of Bip44Levels")
287
+ return self.m_bip32_obj.Depth() == level
288
+
289
+ def DeriveDefaultPath(self) -> Bip44Base:
290
+ """
291
+ Derive the default coin path and return a new Bip44Base object.
292
+
293
+ Returns:
294
+ Bip44Base object: Bip44Base object
295
+
296
+ Raises:
297
+ Bip44DepthError: If the current depth is not suitable for deriving keys
298
+ Bip32KeyError: If the derivation results in an invalid key
299
+ """
300
+ # Derive purpose and coin by default
301
+ bip_obj = self.Purpose().Coin()
302
+
303
+ # Derive the remaining path
304
+ return self.__class__(bip_obj.m_bip32_obj.DerivePath(bip_obj.m_coin_conf.DefaultPath()),
305
+ bip_obj.m_coin_conf)
306
+
307
+ #
308
+ # Protected class methods
309
+ #
310
+
311
+ def _PurposeGeneric(self,
312
+ purpose: int) -> Bip44Base:
313
+ """
314
+ Derive a child key from the purpose and return a new Bip44Base object.
315
+ It shall be called from a child class.
316
+
317
+ Args:
318
+ purpose (int): Purpose
319
+
320
+ Returns:
321
+ Bip44Base object: Bip44Base object
322
+
323
+ Raises:
324
+ Bip44DepthError: If the current depth is not suitable for deriving keys
325
+ Bip32KeyError: If the derivation results in an invalid key
326
+ """
327
+ if not self.IsLevel(Bip44Levels.MASTER):
328
+ raise Bip44DepthError(
329
+ f"Current depth ({self.m_bip32_obj.Depth().ToInt()}) is not suitable for deriving purpose"
330
+ )
331
+
332
+ return self.__class__(self.m_bip32_obj.ChildKey(purpose),
333
+ self.m_coin_conf)
334
+
335
+ def _CoinGeneric(self) -> Bip44Base:
336
+ """
337
+ Derive a child key from the coin type specified at construction and return a new Bip44Base object.
338
+ It shall be called from a child class.
339
+
340
+ Returns:
341
+ Bip44Base object: Bip44Base object
342
+
343
+ Raises:
344
+ Bip44DepthError: If the current depth is not suitable for deriving keys
345
+ Bip32KeyError: If the derivation results in an invalid key
346
+ """
347
+ if not self.IsLevel(Bip44Levels.PURPOSE):
348
+ raise Bip44DepthError(
349
+ f"Current depth ({self.m_bip32_obj.Depth().ToInt()}) is not suitable for deriving coin"
350
+ )
351
+
352
+ coin_idx = self.m_coin_conf.CoinIndex()
353
+
354
+ return self.__class__(self.m_bip32_obj.ChildKey(Bip32KeyIndex.HardenIndex(coin_idx)),
355
+ self.m_coin_conf)
356
+
357
+ def _AccountGeneric(self,
358
+ acc_idx: int) -> Bip44Base:
359
+ """
360
+ Derive a child key from the specified account index and return a new Bip44Base object.
361
+ It shall be called from a child class.
362
+
363
+ Args:
364
+ acc_idx (int): Account index
365
+
366
+ Returns:
367
+ Bip44Base object: Bip44Base object
368
+
369
+ Raises:
370
+ Bip44DepthError: If the current depth is not suitable for deriving keys
371
+ Bip32KeyError: If the derivation results in an invalid key
372
+ """
373
+ if not self.IsLevel(Bip44Levels.COIN):
374
+ raise Bip44DepthError(
375
+ f"Current depth ({self.m_bip32_obj.Depth().ToInt()}) is not suitable for deriving account"
376
+ )
377
+
378
+ return self.__class__(self.m_bip32_obj.ChildKey(Bip32KeyIndex.HardenIndex(acc_idx)),
379
+ self.m_coin_conf)
380
+
381
+ def _ChangeGeneric(self,
382
+ change_type: Bip44Changes) -> Bip44Base:
383
+ """
384
+ Derive a child key from the specified change type and return a new Bip44Base object.
385
+ It shall be called from a child class.
386
+
387
+ Args:
388
+ change_type (Bip44Changes): Change type, must a Bip44Changes enum
389
+
390
+ Returns:
391
+ Bip44Base object: Bip44Base object
392
+
393
+ Raises:
394
+ TypeError: If change type is not a Bip44Changes enum
395
+ Bip44DepthError: If the current depth is not suitable for deriving keys
396
+ Bip32KeyError: If the derivation results in an invalid key
397
+ """
398
+ if not isinstance(change_type, Bip44Changes):
399
+ raise TypeError("Change index is not an enumerative of Bip44Changes")
400
+
401
+ if not self.IsLevel(Bip44Levels.ACCOUNT):
402
+ raise Bip44DepthError(
403
+ f"Current depth ({self.m_bip32_obj.Depth().ToInt()}) is not suitable for deriving change"
404
+ )
405
+
406
+ # Use hardened derivation if not-hardended is not supported
407
+ if not self.m_bip32_obj.IsPublicDerivationSupported():
408
+ change_idx = Bip32KeyIndex.HardenIndex(int(change_type))
409
+ else:
410
+ change_idx = int(change_type)
411
+
412
+ return self.__class__(self.m_bip32_obj.ChildKey(change_idx),
413
+ self.m_coin_conf)
414
+
415
+ def _AddressIndexGeneric(self,
416
+ addr_idx: int) -> Bip44Base:
417
+ """
418
+ Derive a child key from the specified address index and return a new Bip44Base object.
419
+ It shall be called from a child class.
420
+
421
+ Args:
422
+ addr_idx (int): Address index
423
+
424
+ Returns:
425
+ Bip44Base object: Bip44Base object
426
+
427
+ Raises:
428
+ Bip44DepthError: If the current depth is not suitable for deriving keys
429
+ Bip32KeyError: If the derivation results in an invalid key
430
+ """
431
+ if not self.IsLevel(Bip44Levels.CHANGE):
432
+ raise Bip44DepthError(
433
+ f"Current depth ({self.m_bip32_obj.Depth().ToInt()}) is not suitable for deriving address"
434
+ )
435
+
436
+ # Use hardened derivation if not-hardended is not supported
437
+ if not self.m_bip32_obj.IsPublicDerivationSupported():
438
+ addr_idx = Bip32KeyIndex.HardenIndex(addr_idx)
439
+
440
+ return self.__class__(self.m_bip32_obj.ChildKey(addr_idx),
441
+ self.m_coin_conf)
442
+
443
+ #
444
+ # Abstract methods
445
+ #
446
+
447
+ @classmethod
448
+ @abstractmethod
449
+ def FromSeed(cls,
450
+ seed_bytes: bytes,
451
+ coin_type: BipCoins) -> Bip44Base:
452
+ """
453
+ Create a Bip44Base object from the specified seed (e.g. BIP39 seed).
454
+ The test net flag is automatically set when the coin is derived. However, if you want to get the correct master
455
+ or purpose keys, you have to specify here if it's a test net.
456
+
457
+ Args:
458
+ seed_bytes (bytes) : Seed bytes
459
+ coin_type (BipCoins): Coin type (the type depends on the specific child class)
460
+
461
+ Returns:
462
+ Bip44Base object: Bip44Base object
463
+
464
+ Raises:
465
+ TypeError: If coin type is not of the correct type
466
+ ValueError: If the seed is too short
467
+ Bip32KeyError: If the seed is not suitable for master key generation
468
+ """
469
+
470
+ @classmethod
471
+ @abstractmethod
472
+ def FromExtendedKey(cls,
473
+ ex_key_str: str,
474
+ coin_type: BipCoins) -> Bip44Base:
475
+ """
476
+ Create a Bip44Base object from the specified extended key.
477
+
478
+ Args:
479
+ ex_key_str (str) : Extended key string
480
+ coin_type (BipCoins): Coin type (the type depends on the specific child class)
481
+
482
+ Returns:
483
+ Bip44Base object: Bip44Base object
484
+
485
+ Raises:
486
+ TypeError: If coin type is not of the correct type
487
+ Bip32KeyError: If the extended key is not valid
488
+ """
489
+
490
+ # @classmethod
491
+ # @abstractmethod
492
+ # def FromPrivateKey(cls,
493
+ # priv_key: Union[bytes, IPrivateKey],
494
+ # coin_type: BipCoins,
495
+ # key_data: Bip32KeyData) -> Bip44Base:
496
+ # """
497
+ # Create a Bip44Base object from the specified private key and derivation data.
498
+ # If only the private key bytes are specified, the key will be considered a master key with
499
+ # the chain code set to zero, since there is no way to recover the key derivation data.
500
+
501
+ # Args:
502
+ # priv_key (bytes or IPrivateKey): Private key
503
+ # coin_type (BipCoins) : Coin type, shall be a Bip44Coins enum
504
+ # key_data (Bip32KeyData object) : Key data
505
+
506
+ # Returns:
507
+ # Bip44Base object: Bip44Base object
508
+
509
+ # Raises:
510
+ # TypeError: If coin type is not a Bip44Coins enum
511
+ # Bip32KeyError: If the key is not valid
512
+ # """
513
+
514
+ # @classmethod
515
+ # @abstractmethod
516
+ # def FromPublicKey(cls,
517
+ # pub_key: Union[bytes, IPublicKey],
518
+ # coin_type: BipCoins,
519
+ # key_data: Bip32KeyData) -> Bip44Base:
520
+ # """
521
+ # Create a Bip44Base object from the specified public key and derivation data.
522
+ # If only the public key bytes are specified, the key will be considered an account key with
523
+ # the chain code set to zero, since there is no way to recover the key derivation data.
524
+
525
+ # Args:
526
+ # pub_key (bytes or IPublicKey) : Public key
527
+ # coin_type (BipCoins) : Coin type, shall be a Bip44Coins enum
528
+ # key_data (Bip32KeyData object): Key data
529
+
530
+ # Returns:
531
+ # Bip44Base object: Bip44Base object
532
+
533
+ # Raises:
534
+ # TypeError: If coin type is not a Bip44Coins enum
535
+ # Bip32KeyError: If the key is not valid
536
+ # """
537
+
538
+ @abstractmethod
539
+ def Purpose(self) -> Bip44Base:
540
+ """
541
+ Derive a child key from the purpose and return a new Bip44Base object.
542
+
543
+ Returns:
544
+ Bip44Base object: Bip44Base object
545
+
546
+ Raises:
547
+ Bip44DepthError: If current depth is not suitable for deriving keys
548
+ Bip32KeyError: If the derivation results in an invalid key
549
+ """
550
+
551
+ @abstractmethod
552
+ def Coin(self) -> Bip44Base:
553
+ """
554
+ Derive a child key from the coin type specified at construction and return a new Bip44Base object.
555
+
556
+ Returns:
557
+ Bip44Base object: Bip44Base object
558
+
559
+ Raises:
560
+ Bip44DepthError: If current depth is not suitable for deriving keys
561
+ Bip32KeyError: If the derivation results in an invalid key
562
+ """
563
+
564
+ @abstractmethod
565
+ def Account(self,
566
+ acc_idx: int) -> Bip44Base:
567
+ """
568
+ Derive a child key from the specified account index and return a new Bip44Base object.
569
+
570
+ Args:
571
+ acc_idx (int): Account index
572
+
573
+ Returns:
574
+ Bip44Base object: Bip44Base object
575
+
576
+ Raises:
577
+ Bip44DepthError: If current depth is not suitable for deriving keys
578
+ Bip32KeyError: If the derivation results in an invalid key
579
+ """
580
+
581
+ @abstractmethod
582
+ def Change(self,
583
+ change_type: Bip44Changes) -> Bip44Base:
584
+ """
585
+ Derive a child key from the specified change type and return a new Bip44Base object.
586
+
587
+ Args:
588
+ change_type (Bip44Changes): Change type, must a Bip44Changes enum
589
+
590
+ Returns:
591
+ Bip44Base object: Bip44Base object
592
+
593
+ Raises:
594
+ TypeError: If change type is not a Bip44Changes enum
595
+ Bip44DepthError: If current depth is not suitable for deriving keys
596
+ Bip32KeyError: If the derivation results in an invalid key
597
+ """
598
+
599
+ @abstractmethod
600
+ def AddressIndex(self,
601
+ addr_idx: int) -> Bip44Base:
602
+ """
603
+ Derive a child key from the specified address index and return a new Bip44Base object.
604
+
605
+ Args:
606
+ addr_idx (int): Address index
607
+
608
+ Returns:
609
+ Bip44Base object: Bip44Base object
610
+
611
+ Raises:
612
+ Bip44DepthError: If current depth is not suitable for deriving keys
613
+ Bip32KeyError: If the derivation results in an invalid key
614
+ """
615
+
616
+ @staticmethod
617
+ @abstractmethod
618
+ def SpecName() -> str:
619
+ """
620
+ Get specification name.
621
+
622
+ Returns:
623
+ str: Specification name
624
+ """
@@ -0,0 +1,25 @@
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 BIP44 exceptions."""
22
+
23
+
24
+ class Bip44DepthError(Exception):
25
+ """Exception in case of derivation from wrong depth."""