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,152 @@
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 AES-ECB encryption/decryption."""
22
+
23
+
24
+ #
25
+ # Imports
26
+ #
27
+ from typing import Any, Union
28
+
29
+ from Crypto.Cipher import AES
30
+ from Crypto.Util.Padding import pad, unpad
31
+
32
+ from ..misc.algo import AlgoUtils
33
+
34
+
35
+ #
36
+ # Classes
37
+ #
38
+
39
+ class AesEcbEncrypter:
40
+ """
41
+ AES-ECB encrypter class.
42
+ It encrypts data using AES-ECB algorithm.
43
+ """
44
+
45
+ aes: Any
46
+ auto_pad: bool
47
+
48
+ # Constructor
49
+ def __init__(self,
50
+ key: Union[str, bytes]) -> None:
51
+ """
52
+ Construct class.
53
+
54
+ Args:
55
+ key (str or bytes): AES key
56
+ """
57
+ self.aes = AES.new(AlgoUtils.Encode(key), AES.MODE_ECB)
58
+ self.auto_pad = True
59
+
60
+ def AutoPad(self,
61
+ value: bool) -> None:
62
+ """
63
+ Set the auto-pad flag.
64
+
65
+ Args:
66
+ value (bool): Flag value
67
+ """
68
+ self.auto_pad = value
69
+
70
+ def Encrypt(self,
71
+ data: Union[str, bytes]) -> bytes:
72
+ """
73
+ Encrypt data using AES-ECB algorithm.
74
+
75
+ Args:
76
+ data (str or bytes): Data to be encrypted
77
+
78
+ Returns:
79
+ bytes: Encrypted data
80
+ """
81
+ padded_data = self.Pad(data) if self.auto_pad else AlgoUtils.Encode(data)
82
+ return self.aes.encrypt(padded_data)
83
+
84
+ @staticmethod
85
+ def Pad(data: Union[str, bytes]) -> bytes:
86
+ """
87
+ Pad data using PKCS7 algorithm.
88
+
89
+ Args:
90
+ data (str or bytes): Data to be padded
91
+
92
+ Returns:
93
+ bytes: Padded data
94
+ """
95
+ return pad(AlgoUtils.Encode(data), AES.block_size)
96
+
97
+
98
+ class AesEcbDecrypter:
99
+ """
100
+ AES-ECB decrypter class.
101
+ It decrypts data using AES-ECB algorithm.
102
+ """
103
+
104
+ aes: Any
105
+
106
+ def __init__(self,
107
+ key: Union[str, bytes]) -> None:
108
+ """
109
+ Construct class.
110
+
111
+ Args:
112
+ key (str or bytes): AES key
113
+ """
114
+ self.aes = AES.new(AlgoUtils.Encode(key), AES.MODE_ECB)
115
+ self.auto_unpad = True
116
+
117
+ def AutoUnPad(self,
118
+ value: bool) -> None:
119
+ """
120
+ Set the auto-unpad flag.
121
+
122
+ Args:
123
+ value (bool): Flag value
124
+ """
125
+ self.auto_unpad = value
126
+
127
+ def Decrypt(self,
128
+ data: bytes) -> bytes:
129
+ """
130
+ Decrypt data using AES-ECB algorithm.
131
+
132
+ Args:
133
+ data (bytes): Data to be decrypted
134
+
135
+ Returns:
136
+ bytes: Decrypted data
137
+ """
138
+ dec = self.aes.decrypt(data)
139
+ return self.UnPad(dec) if self.auto_unpad else dec
140
+
141
+ @staticmethod
142
+ def UnPad(data: bytes) -> bytes:
143
+ """
144
+ Unpad data using PKCS7 algorithm.
145
+
146
+ Args:
147
+ data (bytes): Data to be unpadded
148
+
149
+ Returns:
150
+ bytes: Unpadded data
151
+ """
152
+ return unpad(data, AES.block_size)
@@ -0,0 +1,191 @@
1
+ # Copyright (c) 2022 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 BLAKE-2 algorithms."""
22
+
23
+ # Imports
24
+ import hashlib
25
+ from abc import ABC, abstractmethod
26
+ from typing import Union
27
+
28
+ from ..misc import AlgoUtils
29
+
30
+
31
+ class Blake2b:
32
+ """
33
+ BLAKE2b class.
34
+ It computes digests using BLAKE2b algorithm.
35
+ """
36
+
37
+ @staticmethod
38
+ def QuickDigest(data: Union[bytes, str],
39
+ digest_size: int,
40
+ key: Union[bytes, str] = b"",
41
+ salt: Union[bytes, str] = b"") -> bytes:
42
+ """
43
+ Compute the digest (quick version).
44
+
45
+ Args:
46
+ data (str or bytes) : Data
47
+ digest_size (int) : Digest size
48
+ key ((str or bytes, optional) : Key (default: empty)
49
+ salt ((str or bytes, optional): Salt (default: empty)
50
+
51
+ Returns:
52
+ bytes: Computed digest
53
+ """
54
+ return hashlib.blake2b(AlgoUtils.Encode(data),
55
+ digest_size=digest_size,
56
+ key=AlgoUtils.Encode(key),
57
+ salt=AlgoUtils.Encode(salt)).digest()
58
+
59
+
60
+ class _Blake2bWithSpecificSize(ABC):
61
+ """Abstract class for Blake2b with specific digest size."""
62
+
63
+ @classmethod
64
+ def QuickDigest(cls,
65
+ data: Union[bytes, str],
66
+ key: Union[bytes, str] = b"",
67
+ salt: Union[bytes, str] = b"") -> bytes:
68
+ """
69
+ Compute the digest (quick version).
70
+
71
+ Args:
72
+ data (str or bytes) : Data
73
+ key (str or bytes, optional) : Key bytes (default: empty)
74
+ salt (str or bytes, optional): Salt bytes (default: empty)
75
+
76
+ Returns:
77
+ bytes: Computed digest
78
+ """
79
+ return Blake2b.QuickDigest(data, cls.DigestSize(), key, salt)
80
+
81
+ @staticmethod
82
+ @abstractmethod
83
+ def DigestSize() -> int:
84
+ """
85
+ Get the digest size in bytes.
86
+
87
+ Returns:
88
+ int: Digest size in bytes
89
+ """
90
+
91
+
92
+ class Blake2b32(_Blake2bWithSpecificSize):
93
+ """
94
+ BLAKE2b-32 class.
95
+ It computes digests using BLAKE2b-32 algorithm.
96
+ """
97
+
98
+ @staticmethod
99
+ def DigestSize() -> int:
100
+ """
101
+ Get the digest size in bytes.
102
+
103
+ Returns:
104
+ int: Digest size in bytes
105
+ """
106
+ return 4
107
+
108
+
109
+ class Blake2b40(_Blake2bWithSpecificSize):
110
+ """
111
+ BLAKE2b-40 class.
112
+ It computes digests using BLAKE2b-40 algorithm.
113
+ """
114
+
115
+ @staticmethod
116
+ def DigestSize() -> int:
117
+ """
118
+ Get the digest size in bytes.
119
+
120
+ Returns:
121
+ int: Digest size in bytes
122
+ """
123
+ return 5
124
+
125
+
126
+ class Blake2b160(_Blake2bWithSpecificSize):
127
+ """
128
+ BLAKE2b-160 class.
129
+ It computes digests using BLAKE2b-160 algorithm.
130
+ """
131
+
132
+ @staticmethod
133
+ def DigestSize() -> int:
134
+ """
135
+ Get the digest size in bytes.
136
+
137
+ Returns:
138
+ int: Digest size in bytes
139
+ """
140
+ return 20
141
+
142
+
143
+ class Blake2b224(_Blake2bWithSpecificSize):
144
+ """
145
+ BLAKE2b-224 class.
146
+ It computes digests using BLAKE2b-224 algorithm.
147
+ """
148
+
149
+ @staticmethod
150
+ def DigestSize() -> int:
151
+ """
152
+ Get the digest size in bytes.
153
+
154
+ Returns:
155
+ int: Digest size in bytes
156
+ """
157
+ return 28
158
+
159
+
160
+ class Blake2b256(_Blake2bWithSpecificSize):
161
+ """
162
+ BLAKE2b-256 class.
163
+ It computes digests using BLAKE2b-256 algorithm.
164
+ """
165
+
166
+ @staticmethod
167
+ def DigestSize() -> int:
168
+ """
169
+ Get the digest size in bytes.
170
+
171
+ Returns:
172
+ int: Digest size in bytes
173
+ """
174
+ return 32
175
+
176
+
177
+ class Blake2b512(_Blake2bWithSpecificSize):
178
+ """
179
+ BLAKE2b-512 class.
180
+ It computes digests using BLAKE2b-512 algorithm.
181
+ """
182
+
183
+ @staticmethod
184
+ def DigestSize() -> int:
185
+ """
186
+ Get the digest size in bytes.
187
+
188
+ Returns:
189
+ int: Digest size in bytes
190
+ """
191
+ return 64
@@ -0,0 +1,101 @@
1
+ # Copyright (c) 2022 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 ChaCha20-Poly1305 algorithm."""
22
+
23
+ # Imports
24
+ from typing import Tuple, Union
25
+
26
+ from Crypto.Cipher import ChaCha20_Poly1305
27
+
28
+ from ..misc import AlgoUtils
29
+
30
+
31
+ class ChaCha20Poly1305:
32
+ """
33
+ ChaCha20-Poly1305 class.
34
+ It decrypts/encrypts data using ChaCha20-Poly1305 algorithm.
35
+ """
36
+
37
+ @staticmethod
38
+ def Decrypt(key: Union[bytes, str],
39
+ nonce: Union[bytes, str],
40
+ assoc_data: Union[bytes, str],
41
+ cipher_text: Union[bytes, str],
42
+ tag: Union[bytes, str]) -> bytes:
43
+ """
44
+ Decrypt data.
45
+
46
+ Args:
47
+ key (str or bytes) : Key
48
+ nonce (str or bytes) : Nonce
49
+ assoc_data (str or bytes): Associated data
50
+ cipher_text (bytes) : Cipher text
51
+ tag (bytes) : Tag
52
+
53
+ Returns:
54
+ bytes: Decrypted data
55
+ """
56
+ cipher = ChaCha20_Poly1305.new(key=AlgoUtils.Encode(key),
57
+ nonce=AlgoUtils.Encode(nonce))
58
+ cipher.update(AlgoUtils.Encode(assoc_data))
59
+ return cipher.decrypt_and_verify(AlgoUtils.Encode(cipher_text), AlgoUtils.Encode(tag))
60
+
61
+ @staticmethod
62
+ def Encrypt(key: Union[bytes, str],
63
+ nonce: Union[bytes, str],
64
+ assoc_data: Union[bytes, str],
65
+ plain_text: Union[bytes, str]) -> Tuple[bytes, bytes]:
66
+ """
67
+ Encrypt data.
68
+
69
+ Args:
70
+ key (str or bytes) : Key
71
+ nonce (str or bytes) : Nonce
72
+ assoc_data (str or bytes): Associated data
73
+ plain_text (str or bytes): Plain text
74
+
75
+ Returns:
76
+ tuple[bytes, bytes]: Cipher text bytes (index 0) and tag bytes (index 1)
77
+ """
78
+ cipher = ChaCha20_Poly1305.new(key=AlgoUtils.Encode(key),
79
+ nonce=AlgoUtils.Encode(nonce))
80
+ cipher.update(AlgoUtils.Encode(assoc_data))
81
+ return cipher.encrypt_and_digest(AlgoUtils.Encode(plain_text))
82
+
83
+ @staticmethod
84
+ def KeySize() -> int:
85
+ """
86
+ Get the key size.
87
+
88
+ Returns:
89
+ int: Key size
90
+ """
91
+ return ChaCha20_Poly1305.key_size
92
+
93
+ @staticmethod
94
+ def TagSize() -> int:
95
+ """
96
+ Get the tag size.
97
+
98
+ Returns:
99
+ int: Tag size
100
+ """
101
+ return 16
@@ -0,0 +1,57 @@
1
+ # Copyright (c) 2022 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 HASH160 algorithm."""
22
+
23
+ # Imports
24
+ from typing import Union
25
+
26
+ from .ripemd import Ripemd160
27
+ from .sha2 import Sha256
28
+
29
+
30
+ class Hash160:
31
+ """
32
+ HASH160 class.
33
+ It computes digests using HASH160 algorithm.
34
+ """
35
+
36
+ @staticmethod
37
+ def QuickDigest(data: Union[bytes, str]) -> bytes:
38
+ """
39
+ Compute the digest (quick version).
40
+
41
+ Args:
42
+ data (str or bytes): Data
43
+
44
+ Returns:
45
+ bytes: Computed digest
46
+ """
47
+ return Ripemd160.QuickDigest(Sha256.QuickDigest(data))
48
+
49
+ @staticmethod
50
+ def DigestSize() -> int:
51
+ """
52
+ Get the digest size in bytes.
53
+
54
+ Returns:
55
+ int: Digest size in bytes
56
+ """
57
+ return Ripemd160.DigestSize()
@@ -0,0 +1,118 @@
1
+ # Copyright (c) 2022 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 SHA-2 algorithms."""
22
+
23
+ # Imports
24
+ import hashlib
25
+ import hmac
26
+ from typing import Tuple, Union
27
+
28
+ from ..misc import AlgoUtils
29
+
30
+
31
+ HMAC_USE_DIGEST: bool = hasattr(hmac, "digest")
32
+
33
+
34
+ class HmacSha256:
35
+ """
36
+ HMAC-SHA256 class.
37
+ It computes digests using HMAC-SHA256 algorithm.
38
+ """
39
+
40
+ @staticmethod
41
+ def QuickDigest(key: Union[bytes, str],
42
+ data: Union[bytes, str]) -> bytes:
43
+ """
44
+ Compute the digest (quick version).
45
+
46
+ Args:
47
+ key (str or bytes) : Key
48
+ data (str or bytes): Data
49
+
50
+ Returns:
51
+ bytes: Computed digest
52
+ """
53
+ # Use digest if available
54
+ if HMAC_USE_DIGEST:
55
+ return hmac.digest(AlgoUtils.Encode(key), AlgoUtils.Encode(data), "sha256")
56
+ return hmac.new(AlgoUtils.Encode(key), AlgoUtils.Encode(data), hashlib.sha256).digest()
57
+
58
+ @staticmethod
59
+ def DigestSize() -> int:
60
+ """
61
+ Get the digest size in bytes.
62
+
63
+ Returns:
64
+ int: Digest size in bytes
65
+ """
66
+ return hashlib.sha256().digest_size
67
+
68
+
69
+ class HmacSha512:
70
+ """
71
+ HMAC-SHA512 class.
72
+ It computes digests using HMAC-SHA512 algorithm.
73
+ """
74
+
75
+ @staticmethod
76
+ def QuickDigest(key: Union[bytes, str],
77
+ data: Union[bytes, str]) -> bytes:
78
+ """
79
+ Compute the digest (quick version).
80
+
81
+ Args:
82
+ key (str or bytes) : Key
83
+ data (str or bytes): Data
84
+
85
+ Returns:
86
+ bytes: Computed digest
87
+ """
88
+
89
+ # Use digest if available
90
+ if HMAC_USE_DIGEST:
91
+ return hmac.digest(AlgoUtils.Encode(key), AlgoUtils.Encode(data), "sha512")
92
+ return hmac.new(AlgoUtils.Encode(key), AlgoUtils.Encode(data), hashlib.sha512).digest()
93
+
94
+ @staticmethod
95
+ def QuickDigestHalves(key: Union[bytes, str],
96
+ data: Union[bytes, str]) -> Tuple[bytes, bytes]:
97
+ """
98
+ Compute the digest and return it split into two halves (quick version).
99
+
100
+ Args:
101
+ key (str or bytes) : Key
102
+ data (str or bytes): Data
103
+
104
+ Returns:
105
+ tuple[bytes, bytes]: Computed digest left part (index 0) and right part (index 1)
106
+ """
107
+ digest_bytes = HmacSha512.QuickDigest(key, data)
108
+ return digest_bytes[:HmacSha512.DigestSize() // 2], digest_bytes[HmacSha512.DigestSize() // 2:]
109
+
110
+ @staticmethod
111
+ def DigestSize() -> int:
112
+ """
113
+ Get the digest size in bytes.
114
+
115
+ Returns:
116
+ int: Digest size in bytes
117
+ """
118
+ return hashlib.sha512().digest_size
@@ -0,0 +1,66 @@
1
+ # Copyright (c) 2022 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 PBKDF2 algorithm."""
22
+
23
+ # Imports
24
+ import hashlib
25
+ from typing import Optional, Union
26
+
27
+ from Crypto.Hash import SHA512
28
+ from Crypto.Protocol.KDF import PBKDF2
29
+
30
+ from ..misc import AlgoUtils
31
+
32
+
33
+ HASHLIB_USE_PBKDF2_SHA512: bool = hasattr(hashlib, "pbkdf2_hmac") # For future changes
34
+
35
+
36
+ class Pbkdf2HmacSha512:
37
+ """
38
+ PBKDF2 HMAC-SHA512 class.
39
+ It derives keys using PBKDF2 HMAC-SHA512 algorithm.
40
+ """
41
+
42
+ @staticmethod
43
+ def DeriveKey(password: Union[bytes, str],
44
+ salt: Union[bytes, str],
45
+ itr_num: int,
46
+ dklen: Optional[int] = None) -> bytes:
47
+ """
48
+ Derive a key.
49
+
50
+ Args:
51
+ password (str or bytes): Password
52
+ salt (str or bytes) : Salt
53
+ itr_num (int) : Iteration number
54
+ dklen (int, optional) : Length of the derived key (default: SHA-512 output length)
55
+
56
+ Returns:
57
+ bytes: Computed result
58
+ """
59
+ if HASHLIB_USE_PBKDF2_SHA512:
60
+ return hashlib.pbkdf2_hmac("sha512", AlgoUtils.Encode(password), AlgoUtils.Encode(salt), itr_num, dklen)
61
+ # Use Cryptodome if not implemented in hashlib
62
+ return PBKDF2(AlgoUtils.Encode(password), # type: ignore [arg-type]
63
+ AlgoUtils.Encode(salt),
64
+ dklen or SHA512.digest_size,
65
+ count=itr_num,
66
+ hmac_hash_module=SHA512)