hyperliquid 0.4.66__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.
Files changed (274) hide show
  1. hyperliquid/__init__.py +7 -0
  2. hyperliquid/ccxt/__init__.py +101 -0
  3. hyperliquid/ccxt/abstract/hyperliquid.py +6 -0
  4. hyperliquid/ccxt/async_support/__init__.py +80 -0
  5. hyperliquid/ccxt/async_support/base/__init__.py +1 -0
  6. hyperliquid/ccxt/async_support/base/exchange.py +2095 -0
  7. hyperliquid/ccxt/async_support/base/throttler.py +50 -0
  8. hyperliquid/ccxt/async_support/base/ws/__init__.py +38 -0
  9. hyperliquid/ccxt/async_support/base/ws/aiohttp_client.py +147 -0
  10. hyperliquid/ccxt/async_support/base/ws/cache.py +213 -0
  11. hyperliquid/ccxt/async_support/base/ws/client.py +214 -0
  12. hyperliquid/ccxt/async_support/base/ws/fast_client.py +97 -0
  13. hyperliquid/ccxt/async_support/base/ws/functions.py +59 -0
  14. hyperliquid/ccxt/async_support/base/ws/future.py +69 -0
  15. hyperliquid/ccxt/async_support/base/ws/order_book.py +78 -0
  16. hyperliquid/ccxt/async_support/base/ws/order_book_side.py +174 -0
  17. hyperliquid/ccxt/async_support/hyperliquid.py +3446 -0
  18. hyperliquid/ccxt/base/__init__.py +27 -0
  19. hyperliquid/ccxt/base/decimal_to_precision.py +174 -0
  20. hyperliquid/ccxt/base/errors.py +267 -0
  21. hyperliquid/ccxt/base/exchange.py +6767 -0
  22. hyperliquid/ccxt/base/precise.py +297 -0
  23. hyperliquid/ccxt/base/types.py +577 -0
  24. hyperliquid/ccxt/hyperliquid.py +3445 -0
  25. hyperliquid/ccxt/pro/__init__.py +21 -0
  26. hyperliquid/ccxt/pro/hyperliquid.py +997 -0
  27. hyperliquid/ccxt/static_dependencies/__init__.py +1 -0
  28. hyperliquid/ccxt/static_dependencies/ecdsa/__init__.py +14 -0
  29. hyperliquid/ccxt/static_dependencies/ecdsa/_version.py +520 -0
  30. hyperliquid/ccxt/static_dependencies/ecdsa/curves.py +56 -0
  31. hyperliquid/ccxt/static_dependencies/ecdsa/der.py +221 -0
  32. hyperliquid/ccxt/static_dependencies/ecdsa/ecdsa.py +310 -0
  33. hyperliquid/ccxt/static_dependencies/ecdsa/ellipticcurve.py +197 -0
  34. hyperliquid/ccxt/static_dependencies/ecdsa/keys.py +332 -0
  35. hyperliquid/ccxt/static_dependencies/ecdsa/numbertheory.py +531 -0
  36. hyperliquid/ccxt/static_dependencies/ecdsa/rfc6979.py +100 -0
  37. hyperliquid/ccxt/static_dependencies/ecdsa/util.py +266 -0
  38. hyperliquid/ccxt/static_dependencies/ethereum/__init__.py +7 -0
  39. hyperliquid/ccxt/static_dependencies/ethereum/abi/__init__.py +16 -0
  40. hyperliquid/ccxt/static_dependencies/ethereum/abi/abi.py +19 -0
  41. hyperliquid/ccxt/static_dependencies/ethereum/abi/base.py +152 -0
  42. hyperliquid/ccxt/static_dependencies/ethereum/abi/codec.py +217 -0
  43. hyperliquid/ccxt/static_dependencies/ethereum/abi/constants.py +3 -0
  44. hyperliquid/ccxt/static_dependencies/ethereum/abi/decoding.py +565 -0
  45. hyperliquid/ccxt/static_dependencies/ethereum/abi/encoding.py +720 -0
  46. hyperliquid/ccxt/static_dependencies/ethereum/abi/exceptions.py +139 -0
  47. hyperliquid/ccxt/static_dependencies/ethereum/abi/grammar.py +443 -0
  48. hyperliquid/ccxt/static_dependencies/ethereum/abi/packed.py +13 -0
  49. hyperliquid/ccxt/static_dependencies/ethereum/abi/py.typed +0 -0
  50. hyperliquid/ccxt/static_dependencies/ethereum/abi/registry.py +643 -0
  51. hyperliquid/ccxt/static_dependencies/ethereum/abi/tools/__init__.py +3 -0
  52. hyperliquid/ccxt/static_dependencies/ethereum/abi/tools/_strategies.py +230 -0
  53. hyperliquid/ccxt/static_dependencies/ethereum/abi/utils/__init__.py +0 -0
  54. hyperliquid/ccxt/static_dependencies/ethereum/abi/utils/numeric.py +83 -0
  55. hyperliquid/ccxt/static_dependencies/ethereum/abi/utils/padding.py +27 -0
  56. hyperliquid/ccxt/static_dependencies/ethereum/abi/utils/string.py +19 -0
  57. hyperliquid/ccxt/static_dependencies/ethereum/account/__init__.py +3 -0
  58. hyperliquid/ccxt/static_dependencies/ethereum/account/encode_typed_data/__init__.py +4 -0
  59. hyperliquid/ccxt/static_dependencies/ethereum/account/encode_typed_data/encoding_and_hashing.py +239 -0
  60. hyperliquid/ccxt/static_dependencies/ethereum/account/encode_typed_data/helpers.py +40 -0
  61. hyperliquid/ccxt/static_dependencies/ethereum/account/messages.py +263 -0
  62. hyperliquid/ccxt/static_dependencies/ethereum/account/py.typed +0 -0
  63. hyperliquid/ccxt/static_dependencies/ethereum/hexbytes/__init__.py +5 -0
  64. hyperliquid/ccxt/static_dependencies/ethereum/hexbytes/_utils.py +54 -0
  65. hyperliquid/ccxt/static_dependencies/ethereum/hexbytes/main.py +65 -0
  66. hyperliquid/ccxt/static_dependencies/ethereum/hexbytes/py.typed +0 -0
  67. hyperliquid/ccxt/static_dependencies/ethereum/typing/__init__.py +63 -0
  68. hyperliquid/ccxt/static_dependencies/ethereum/typing/abi.py +6 -0
  69. hyperliquid/ccxt/static_dependencies/ethereum/typing/bls.py +7 -0
  70. hyperliquid/ccxt/static_dependencies/ethereum/typing/discovery.py +5 -0
  71. hyperliquid/ccxt/static_dependencies/ethereum/typing/encoding.py +7 -0
  72. hyperliquid/ccxt/static_dependencies/ethereum/typing/enums.py +17 -0
  73. hyperliquid/ccxt/static_dependencies/ethereum/typing/ethpm.py +9 -0
  74. hyperliquid/ccxt/static_dependencies/ethereum/typing/evm.py +20 -0
  75. hyperliquid/ccxt/static_dependencies/ethereum/typing/networks.py +1122 -0
  76. hyperliquid/ccxt/static_dependencies/ethereum/typing/py.typed +0 -0
  77. hyperliquid/ccxt/static_dependencies/ethereum/utils/__init__.py +115 -0
  78. hyperliquid/ccxt/static_dependencies/ethereum/utils/abi.py +72 -0
  79. hyperliquid/ccxt/static_dependencies/ethereum/utils/address.py +171 -0
  80. hyperliquid/ccxt/static_dependencies/ethereum/utils/applicators.py +151 -0
  81. hyperliquid/ccxt/static_dependencies/ethereum/utils/conversions.py +190 -0
  82. hyperliquid/ccxt/static_dependencies/ethereum/utils/currency.py +107 -0
  83. hyperliquid/ccxt/static_dependencies/ethereum/utils/curried/__init__.py +269 -0
  84. hyperliquid/ccxt/static_dependencies/ethereum/utils/debug.py +20 -0
  85. hyperliquid/ccxt/static_dependencies/ethereum/utils/decorators.py +132 -0
  86. hyperliquid/ccxt/static_dependencies/ethereum/utils/encoding.py +6 -0
  87. hyperliquid/ccxt/static_dependencies/ethereum/utils/exceptions.py +4 -0
  88. hyperliquid/ccxt/static_dependencies/ethereum/utils/functional.py +75 -0
  89. hyperliquid/ccxt/static_dependencies/ethereum/utils/hexadecimal.py +74 -0
  90. hyperliquid/ccxt/static_dependencies/ethereum/utils/humanize.py +188 -0
  91. hyperliquid/ccxt/static_dependencies/ethereum/utils/logging.py +159 -0
  92. hyperliquid/ccxt/static_dependencies/ethereum/utils/module_loading.py +31 -0
  93. hyperliquid/ccxt/static_dependencies/ethereum/utils/numeric.py +43 -0
  94. hyperliquid/ccxt/static_dependencies/ethereum/utils/py.typed +0 -0
  95. hyperliquid/ccxt/static_dependencies/ethereum/utils/toolz.py +76 -0
  96. hyperliquid/ccxt/static_dependencies/ethereum/utils/types.py +54 -0
  97. hyperliquid/ccxt/static_dependencies/ethereum/utils/typing/__init__.py +18 -0
  98. hyperliquid/ccxt/static_dependencies/ethereum/utils/typing/misc.py +14 -0
  99. hyperliquid/ccxt/static_dependencies/ethereum/utils/units.py +31 -0
  100. hyperliquid/ccxt/static_dependencies/keccak/__init__.py +3 -0
  101. hyperliquid/ccxt/static_dependencies/keccak/keccak.py +197 -0
  102. hyperliquid/ccxt/static_dependencies/lark/__init__.py +38 -0
  103. hyperliquid/ccxt/static_dependencies/lark/__pyinstaller/__init__.py +6 -0
  104. hyperliquid/ccxt/static_dependencies/lark/__pyinstaller/hook-lark.py +14 -0
  105. hyperliquid/ccxt/static_dependencies/lark/ast_utils.py +59 -0
  106. hyperliquid/ccxt/static_dependencies/lark/common.py +86 -0
  107. hyperliquid/ccxt/static_dependencies/lark/exceptions.py +292 -0
  108. hyperliquid/ccxt/static_dependencies/lark/grammar.py +130 -0
  109. hyperliquid/ccxt/static_dependencies/lark/grammars/__init__.py +0 -0
  110. hyperliquid/ccxt/static_dependencies/lark/indenter.py +143 -0
  111. hyperliquid/ccxt/static_dependencies/lark/lark.py +658 -0
  112. hyperliquid/ccxt/static_dependencies/lark/lexer.py +678 -0
  113. hyperliquid/ccxt/static_dependencies/lark/load_grammar.py +1428 -0
  114. hyperliquid/ccxt/static_dependencies/lark/parse_tree_builder.py +391 -0
  115. hyperliquid/ccxt/static_dependencies/lark/parser_frontends.py +257 -0
  116. hyperliquid/ccxt/static_dependencies/lark/parsers/__init__.py +0 -0
  117. hyperliquid/ccxt/static_dependencies/lark/parsers/cyk.py +340 -0
  118. hyperliquid/ccxt/static_dependencies/lark/parsers/earley.py +314 -0
  119. hyperliquid/ccxt/static_dependencies/lark/parsers/earley_common.py +42 -0
  120. hyperliquid/ccxt/static_dependencies/lark/parsers/earley_forest.py +801 -0
  121. hyperliquid/ccxt/static_dependencies/lark/parsers/grammar_analysis.py +203 -0
  122. hyperliquid/ccxt/static_dependencies/lark/parsers/lalr_analysis.py +332 -0
  123. hyperliquid/ccxt/static_dependencies/lark/parsers/lalr_interactive_parser.py +158 -0
  124. hyperliquid/ccxt/static_dependencies/lark/parsers/lalr_parser.py +122 -0
  125. hyperliquid/ccxt/static_dependencies/lark/parsers/lalr_parser_state.py +110 -0
  126. hyperliquid/ccxt/static_dependencies/lark/parsers/xearley.py +165 -0
  127. hyperliquid/ccxt/static_dependencies/lark/py.typed +0 -0
  128. hyperliquid/ccxt/static_dependencies/lark/reconstruct.py +107 -0
  129. hyperliquid/ccxt/static_dependencies/lark/tools/__init__.py +70 -0
  130. hyperliquid/ccxt/static_dependencies/lark/tools/nearley.py +202 -0
  131. hyperliquid/ccxt/static_dependencies/lark/tools/serialize.py +32 -0
  132. hyperliquid/ccxt/static_dependencies/lark/tools/standalone.py +196 -0
  133. hyperliquid/ccxt/static_dependencies/lark/tree.py +267 -0
  134. hyperliquid/ccxt/static_dependencies/lark/tree_matcher.py +186 -0
  135. hyperliquid/ccxt/static_dependencies/lark/tree_templates.py +180 -0
  136. hyperliquid/ccxt/static_dependencies/lark/utils.py +343 -0
  137. hyperliquid/ccxt/static_dependencies/lark/visitors.py +596 -0
  138. hyperliquid/ccxt/static_dependencies/marshmallow/__init__.py +81 -0
  139. hyperliquid/ccxt/static_dependencies/marshmallow/base.py +65 -0
  140. hyperliquid/ccxt/static_dependencies/marshmallow/class_registry.py +94 -0
  141. hyperliquid/ccxt/static_dependencies/marshmallow/decorators.py +231 -0
  142. hyperliquid/ccxt/static_dependencies/marshmallow/error_store.py +60 -0
  143. hyperliquid/ccxt/static_dependencies/marshmallow/exceptions.py +71 -0
  144. hyperliquid/ccxt/static_dependencies/marshmallow/fields.py +2114 -0
  145. hyperliquid/ccxt/static_dependencies/marshmallow/orderedset.py +89 -0
  146. hyperliquid/ccxt/static_dependencies/marshmallow/py.typed +0 -0
  147. hyperliquid/ccxt/static_dependencies/marshmallow/schema.py +1228 -0
  148. hyperliquid/ccxt/static_dependencies/marshmallow/types.py +12 -0
  149. hyperliquid/ccxt/static_dependencies/marshmallow/utils.py +378 -0
  150. hyperliquid/ccxt/static_dependencies/marshmallow/validate.py +678 -0
  151. hyperliquid/ccxt/static_dependencies/marshmallow/warnings.py +2 -0
  152. hyperliquid/ccxt/static_dependencies/marshmallow_dataclass/__init__.py +1047 -0
  153. hyperliquid/ccxt/static_dependencies/marshmallow_dataclass/collection_field.py +51 -0
  154. hyperliquid/ccxt/static_dependencies/marshmallow_dataclass/lazy_class_attribute.py +45 -0
  155. hyperliquid/ccxt/static_dependencies/marshmallow_dataclass/mypy.py +71 -0
  156. hyperliquid/ccxt/static_dependencies/marshmallow_dataclass/py.typed +0 -0
  157. hyperliquid/ccxt/static_dependencies/marshmallow_dataclass/typing.py +14 -0
  158. hyperliquid/ccxt/static_dependencies/marshmallow_dataclass/union_field.py +82 -0
  159. hyperliquid/ccxt/static_dependencies/marshmallow_oneofschema/__init__.py +1 -0
  160. hyperliquid/ccxt/static_dependencies/marshmallow_oneofschema/one_of_schema.py +193 -0
  161. hyperliquid/ccxt/static_dependencies/marshmallow_oneofschema/py.typed +0 -0
  162. hyperliquid/ccxt/static_dependencies/msgpack/__init__.py +55 -0
  163. hyperliquid/ccxt/static_dependencies/msgpack/exceptions.py +48 -0
  164. hyperliquid/ccxt/static_dependencies/msgpack/ext.py +168 -0
  165. hyperliquid/ccxt/static_dependencies/msgpack/fallback.py +951 -0
  166. hyperliquid/ccxt/static_dependencies/parsimonious/__init__.py +10 -0
  167. hyperliquid/ccxt/static_dependencies/parsimonious/exceptions.py +105 -0
  168. hyperliquid/ccxt/static_dependencies/parsimonious/expressions.py +479 -0
  169. hyperliquid/ccxt/static_dependencies/parsimonious/grammar.py +487 -0
  170. hyperliquid/ccxt/static_dependencies/parsimonious/nodes.py +325 -0
  171. hyperliquid/ccxt/static_dependencies/parsimonious/utils.py +40 -0
  172. hyperliquid/ccxt/static_dependencies/starknet/__init__.py +0 -0
  173. hyperliquid/ccxt/static_dependencies/starknet/abi/v0/__init__.py +2 -0
  174. hyperliquid/ccxt/static_dependencies/starknet/abi/v0/model.py +44 -0
  175. hyperliquid/ccxt/static_dependencies/starknet/abi/v0/parser.py +216 -0
  176. hyperliquid/ccxt/static_dependencies/starknet/abi/v0/schemas.py +72 -0
  177. hyperliquid/ccxt/static_dependencies/starknet/abi/v0/shape.py +63 -0
  178. hyperliquid/ccxt/static_dependencies/starknet/abi/v1/__init__.py +2 -0
  179. hyperliquid/ccxt/static_dependencies/starknet/abi/v1/model.py +39 -0
  180. hyperliquid/ccxt/static_dependencies/starknet/abi/v1/parser.py +220 -0
  181. hyperliquid/ccxt/static_dependencies/starknet/abi/v1/parser_transformer.py +179 -0
  182. hyperliquid/ccxt/static_dependencies/starknet/abi/v1/schemas.py +66 -0
  183. hyperliquid/ccxt/static_dependencies/starknet/abi/v1/shape.py +47 -0
  184. hyperliquid/ccxt/static_dependencies/starknet/abi/v2/__init__.py +2 -0
  185. hyperliquid/ccxt/static_dependencies/starknet/abi/v2/model.py +89 -0
  186. hyperliquid/ccxt/static_dependencies/starknet/abi/v2/parser.py +293 -0
  187. hyperliquid/ccxt/static_dependencies/starknet/abi/v2/parser_transformer.py +192 -0
  188. hyperliquid/ccxt/static_dependencies/starknet/abi/v2/schemas.py +132 -0
  189. hyperliquid/ccxt/static_dependencies/starknet/abi/v2/shape.py +107 -0
  190. hyperliquid/ccxt/static_dependencies/starknet/cairo/__init__.py +0 -0
  191. hyperliquid/ccxt/static_dependencies/starknet/cairo/data_types.py +123 -0
  192. hyperliquid/ccxt/static_dependencies/starknet/cairo/deprecated_parse/__init__.py +0 -0
  193. hyperliquid/ccxt/static_dependencies/starknet/cairo/deprecated_parse/cairo_types.py +77 -0
  194. hyperliquid/ccxt/static_dependencies/starknet/cairo/deprecated_parse/parser.py +46 -0
  195. hyperliquid/ccxt/static_dependencies/starknet/cairo/deprecated_parse/parser_transformer.py +138 -0
  196. hyperliquid/ccxt/static_dependencies/starknet/cairo/felt.py +64 -0
  197. hyperliquid/ccxt/static_dependencies/starknet/cairo/type_parser.py +121 -0
  198. hyperliquid/ccxt/static_dependencies/starknet/cairo/v1/__init__.py +0 -0
  199. hyperliquid/ccxt/static_dependencies/starknet/cairo/v1/type_parser.py +59 -0
  200. hyperliquid/ccxt/static_dependencies/starknet/cairo/v2/__init__.py +0 -0
  201. hyperliquid/ccxt/static_dependencies/starknet/cairo/v2/type_parser.py +77 -0
  202. hyperliquid/ccxt/static_dependencies/starknet/ccxt_utils.py +7 -0
  203. hyperliquid/ccxt/static_dependencies/starknet/common.py +15 -0
  204. hyperliquid/ccxt/static_dependencies/starknet/constants.py +39 -0
  205. hyperliquid/ccxt/static_dependencies/starknet/hash/__init__.py +0 -0
  206. hyperliquid/ccxt/static_dependencies/starknet/hash/address.py +79 -0
  207. hyperliquid/ccxt/static_dependencies/starknet/hash/compiled_class_hash_objects.py +111 -0
  208. hyperliquid/ccxt/static_dependencies/starknet/hash/selector.py +16 -0
  209. hyperliquid/ccxt/static_dependencies/starknet/hash/storage.py +12 -0
  210. hyperliquid/ccxt/static_dependencies/starknet/hash/utils.py +78 -0
  211. hyperliquid/ccxt/static_dependencies/starknet/models/__init__.py +0 -0
  212. hyperliquid/ccxt/static_dependencies/starknet/models/typed_data.py +45 -0
  213. hyperliquid/ccxt/static_dependencies/starknet/serialization/__init__.py +24 -0
  214. hyperliquid/ccxt/static_dependencies/starknet/serialization/_calldata_reader.py +40 -0
  215. hyperliquid/ccxt/static_dependencies/starknet/serialization/_context.py +142 -0
  216. hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/__init__.py +10 -0
  217. hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/_common.py +82 -0
  218. hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/array_serializer.py +43 -0
  219. hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/bool_serializer.py +37 -0
  220. hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/byte_array_serializer.py +66 -0
  221. hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/cairo_data_serializer.py +71 -0
  222. hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/enum_serializer.py +71 -0
  223. hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/felt_serializer.py +50 -0
  224. hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/named_tuple_serializer.py +58 -0
  225. hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/option_serializer.py +43 -0
  226. hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/output_serializer.py +40 -0
  227. hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/payload_serializer.py +72 -0
  228. hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/struct_serializer.py +36 -0
  229. hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/tuple_serializer.py +36 -0
  230. hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/uint256_serializer.py +76 -0
  231. hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/uint_serializer.py +100 -0
  232. hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/unit_serializer.py +32 -0
  233. hyperliquid/ccxt/static_dependencies/starknet/serialization/errors.py +10 -0
  234. hyperliquid/ccxt/static_dependencies/starknet/serialization/factory.py +229 -0
  235. hyperliquid/ccxt/static_dependencies/starknet/serialization/function_serialization_adapter.py +110 -0
  236. hyperliquid/ccxt/static_dependencies/starknet/serialization/tuple_dataclass.py +59 -0
  237. hyperliquid/ccxt/static_dependencies/starknet/utils/__init__.py +0 -0
  238. hyperliquid/ccxt/static_dependencies/starknet/utils/constructor_args_translator.py +86 -0
  239. hyperliquid/ccxt/static_dependencies/starknet/utils/iterable.py +13 -0
  240. hyperliquid/ccxt/static_dependencies/starknet/utils/schema.py +13 -0
  241. hyperliquid/ccxt/static_dependencies/starknet/utils/typed_data.py +182 -0
  242. hyperliquid/ccxt/static_dependencies/starkware/__init__.py +0 -0
  243. hyperliquid/ccxt/static_dependencies/starkware/crypto/__init__.py +0 -0
  244. hyperliquid/ccxt/static_dependencies/starkware/crypto/fast_pedersen_hash.py +50 -0
  245. hyperliquid/ccxt/static_dependencies/starkware/crypto/math_utils.py +78 -0
  246. hyperliquid/ccxt/static_dependencies/starkware/crypto/signature.py +2344 -0
  247. hyperliquid/ccxt/static_dependencies/starkware/crypto/utils.py +63 -0
  248. hyperliquid/ccxt/static_dependencies/sympy/__init__.py +0 -0
  249. hyperliquid/ccxt/static_dependencies/sympy/core/__init__.py +0 -0
  250. hyperliquid/ccxt/static_dependencies/sympy/core/intfunc.py +35 -0
  251. hyperliquid/ccxt/static_dependencies/sympy/external/__init__.py +0 -0
  252. hyperliquid/ccxt/static_dependencies/sympy/external/gmpy.py +345 -0
  253. hyperliquid/ccxt/static_dependencies/sympy/external/importtools.py +187 -0
  254. hyperliquid/ccxt/static_dependencies/sympy/external/ntheory.py +637 -0
  255. hyperliquid/ccxt/static_dependencies/sympy/external/pythonmpq.py +341 -0
  256. hyperliquid/ccxt/static_dependencies/toolz/__init__.py +26 -0
  257. hyperliquid/ccxt/static_dependencies/toolz/_signatures.py +784 -0
  258. hyperliquid/ccxt/static_dependencies/toolz/_version.py +520 -0
  259. hyperliquid/ccxt/static_dependencies/toolz/compatibility.py +30 -0
  260. hyperliquid/ccxt/static_dependencies/toolz/curried/__init__.py +101 -0
  261. hyperliquid/ccxt/static_dependencies/toolz/curried/exceptions.py +22 -0
  262. hyperliquid/ccxt/static_dependencies/toolz/curried/operator.py +22 -0
  263. hyperliquid/ccxt/static_dependencies/toolz/dicttoolz.py +339 -0
  264. hyperliquid/ccxt/static_dependencies/toolz/functoolz.py +1049 -0
  265. hyperliquid/ccxt/static_dependencies/toolz/itertoolz.py +1057 -0
  266. hyperliquid/ccxt/static_dependencies/toolz/recipes.py +46 -0
  267. hyperliquid/ccxt/static_dependencies/toolz/utils.py +9 -0
  268. hyperliquid/ccxt/static_dependencies/typing_inspect/__init__.py +0 -0
  269. hyperliquid/ccxt/static_dependencies/typing_inspect/typing_inspect.py +851 -0
  270. hyperliquid-0.4.66.dist-info/LICENSE +21 -0
  271. hyperliquid-0.4.66.dist-info/METADATA +219 -0
  272. hyperliquid-0.4.66.dist-info/RECORD +274 -0
  273. hyperliquid-0.4.66.dist-info/WHEEL +5 -0
  274. hyperliquid-0.4.66.dist-info/top_level.txt +1 -0
@@ -0,0 +1,110 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass, field
4
+ from typing import Dict, List, Set, Tuple
5
+
6
+ from ..cairo.felt import CairoData
7
+ from .data_serializers.output_serializer import (
8
+ OutputSerializer,
9
+ )
10
+ from .data_serializers.payload_serializer import (
11
+ PayloadSerializer,
12
+ )
13
+ from .errors import InvalidTypeException
14
+ from .tuple_dataclass import TupleDataclass
15
+
16
+
17
+ @dataclass
18
+ class FunctionSerializationAdapter:
19
+ """
20
+ Class serializing ``*args`` and ``**kwargs`` by adapting them to function inputs.
21
+ """
22
+
23
+ inputs_serializer: PayloadSerializer
24
+ outputs_deserializer: PayloadSerializer
25
+
26
+ expected_args: Tuple[str] = field(init=False)
27
+
28
+ def __post_init__(self):
29
+ self.expected_args = tuple(
30
+ self.inputs_serializer.serializers.keys()
31
+ ) # pyright: ignore
32
+
33
+ def serialize(self, *args, **kwargs) -> CairoData:
34
+ """
35
+ Method using args and kwargs to match members and serialize them separately.
36
+
37
+ :return: Members serialized separately in SerializedPayload.
38
+ """
39
+ named_arguments = self._merge_arguments(args, kwargs)
40
+ return self.inputs_serializer.serialize(named_arguments)
41
+
42
+ def deserialize(self, data: List[int]) -> TupleDataclass:
43
+ """
44
+ Deserializes data into TupleDataclass containing python representations.
45
+
46
+ :return: cairo data.
47
+ """
48
+ return self.outputs_deserializer.deserialize(data)
49
+
50
+ def _merge_arguments(self, args: Tuple, kwargs: Dict) -> Dict:
51
+ """
52
+ Merges positional and keyed arguments.
53
+ """
54
+ # After this line we know that len(args) <= len(self.expected_args)
55
+ self._ensure_no_unnecessary_positional_args(args)
56
+
57
+ named_arguments = dict(kwargs)
58
+ for arg, input_name in zip(args, self.expected_args):
59
+ if input_name in kwargs:
60
+ raise InvalidTypeException(
61
+ f"Both positional and named argument provided for '{input_name}'."
62
+ )
63
+ named_arguments[input_name] = arg
64
+
65
+ expected_args = set(self.expected_args)
66
+ provided_args = set(named_arguments.keys())
67
+
68
+ # named_arguments might have unnecessary arguments coming from kwargs (we ensure that
69
+ # len(args) <= len(self.expected_args) above)
70
+ self._ensure_no_unnecessary_args(expected_args, provided_args)
71
+
72
+ # there might be some argument missing (not provided)
73
+ self._ensure_no_missing_args(expected_args, provided_args)
74
+
75
+ return named_arguments
76
+
77
+ def _ensure_no_unnecessary_positional_args(self, args: Tuple):
78
+ if len(args) > len(self.expected_args):
79
+ raise InvalidTypeException(
80
+ f"Provided {len(args)} positional arguments, {len(self.expected_args)} possible."
81
+ )
82
+
83
+ @staticmethod
84
+ def _ensure_no_unnecessary_args(expected_args: Set[str], provided_args: Set[str]):
85
+ excessive_arguments = provided_args - expected_args
86
+ if excessive_arguments:
87
+ raise InvalidTypeException(
88
+ f"Unnecessary named arguments provided: '{', '.join(excessive_arguments)}'."
89
+ )
90
+
91
+ @staticmethod
92
+ def _ensure_no_missing_args(expected_args: Set[str], provided_args: Set[str]):
93
+ missing_arguments = expected_args - provided_args
94
+ if missing_arguments:
95
+ raise InvalidTypeException(
96
+ f"Missing arguments: '{', '.join(missing_arguments)}'."
97
+ )
98
+
99
+
100
+ @dataclass
101
+ class FunctionSerializationAdapterV1(FunctionSerializationAdapter):
102
+ outputs_deserializer: OutputSerializer
103
+
104
+ def deserialize(self, data: List[int]) -> Tuple:
105
+ """
106
+ Deserializes data into TupleDataclass containing python representations.
107
+
108
+ :return: cairo data.
109
+ """
110
+ return self.outputs_deserializer.deserialize(data)
@@ -0,0 +1,59 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass, fields, make_dataclass
4
+ from typing import Dict, Optional, Tuple
5
+
6
+
7
+ @dataclass(frozen=True, eq=False)
8
+ class TupleDataclass:
9
+ """
10
+ Dataclass that behaves like a tuple at the same time. Used when data has defined order and names.
11
+ For instance in case of named tuples or function responses.
12
+ """
13
+
14
+ # getattr is called when attribute is not found in object. For instance when using object.unknown_attribute.
15
+ # This way pyright will know that there might be some arguments it doesn't know about and will stop complaining
16
+ # about some fields that don't exist statically.
17
+ def __getattr__(self, item):
18
+ # This should always fail - only attributes that don't exist end up in here.
19
+ # We use __getattribute__ to get the native error.
20
+ return super().__getattribute__(item)
21
+
22
+ def __getitem__(self, item: int):
23
+ field = fields(self)[item]
24
+ return getattr(self, field.name)
25
+
26
+ def __iter__(self):
27
+ return (getattr(self, field.name) for field in fields(self))
28
+
29
+ def as_tuple(self) -> Tuple:
30
+ """
31
+ Creates a regular tuple from TupleDataclass.
32
+ """
33
+ return tuple(self)
34
+
35
+ def as_dict(self) -> Dict:
36
+ """
37
+ Creates a regular dict from TupleDataclass.
38
+ """
39
+ return {field.name: getattr(self, field.name) for field in fields(self)}
40
+
41
+ # Added for backward compatibility with previous implementation based on NamedTuple
42
+ def _asdict(self):
43
+ return self.as_dict()
44
+
45
+ def __eq__(self, other):
46
+ if isinstance(other, TupleDataclass):
47
+ return self.as_tuple() == other.as_tuple()
48
+ return self.as_tuple() == other
49
+
50
+ @staticmethod
51
+ def from_dict(data: Dict, *, name: Optional[str] = None) -> TupleDataclass:
52
+ result_class = make_dataclass(
53
+ name or "TupleDataclass",
54
+ fields=[(key, type(value)) for key, value in data.items()],
55
+ bases=(TupleDataclass,),
56
+ frozen=True,
57
+ eq=False,
58
+ )
59
+ return result_class(**data)
@@ -0,0 +1,86 @@
1
+ from typing import List, Optional, Union
2
+
3
+ from ..abi.v2 import shape as ShapeV2
4
+ from ..abi.v0 import AbiParser as AbiParserV0
5
+ from ..abi.v1 import AbiParser as AbiParserV1
6
+ from ..abi.v2 import AbiParser as AbiParserV2
7
+ from ..serialization import (
8
+ FunctionSerializationAdapter,
9
+ serializer_for_function,
10
+ )
11
+ from ..serialization.factory import (
12
+ serializer_for_constructor_v2,
13
+ serializer_for_function_v1,
14
+ )
15
+
16
+
17
+ def translate_constructor_args(
18
+ abi: List, constructor_args: Optional[Union[List, dict]], *, cairo_version: int = 1
19
+ ) -> List[int]:
20
+ serializer = (
21
+ _get_constructor_serializer_v1(abi)
22
+ if cairo_version == 1
23
+ else _get_constructor_serializer_v0(abi)
24
+ )
25
+
26
+ if serializer is None or len(serializer.inputs_serializer.serializers) == 0:
27
+ return []
28
+
29
+ if not constructor_args:
30
+ raise ValueError(
31
+ "Provided contract has a constructor and no arguments were provided."
32
+ )
33
+
34
+ args, kwargs = (
35
+ ([], constructor_args)
36
+ if isinstance(constructor_args, dict)
37
+ else (constructor_args, {})
38
+ )
39
+ return serializer.serialize(*args, **kwargs)
40
+
41
+
42
+ def _get_constructor_serializer_v1(abi: List) -> Optional[FunctionSerializationAdapter]:
43
+ if _is_abi_v2(abi):
44
+ parsed = AbiParserV2(abi).parse()
45
+ constructor = parsed.constructor
46
+
47
+ if constructor is None or not constructor.inputs:
48
+ return None
49
+
50
+ return serializer_for_constructor_v2(constructor)
51
+
52
+ parsed = AbiParserV1(abi).parse()
53
+ constructor = parsed.functions.get("constructor", None)
54
+
55
+ # Constructor might not accept any arguments
56
+ if constructor is None or not constructor.inputs:
57
+ return None
58
+
59
+ return serializer_for_function_v1(constructor)
60
+
61
+
62
+ def _is_abi_v2(abi: List) -> bool:
63
+ for entry in abi:
64
+ if entry["type"] in [
65
+ ShapeV2.CONSTRUCTOR_ENTRY,
66
+ ShapeV2.L1_HANDLER_ENTRY,
67
+ ShapeV2.INTERFACE_ENTRY,
68
+ ShapeV2.IMPL_ENTRY,
69
+ ]:
70
+ return True
71
+ if entry["type"] == ShapeV2.EVENT_ENTRY:
72
+ if "inputs" in entry:
73
+ return False
74
+ if "kind" in entry:
75
+ return True
76
+ return False
77
+
78
+
79
+ def _get_constructor_serializer_v0(abi: List) -> Optional[FunctionSerializationAdapter]:
80
+ parsed = AbiParserV0(abi).parse()
81
+
82
+ # Constructor might not accept any arguments
83
+ if not parsed.constructor or not parsed.constructor.inputs:
84
+ return None
85
+
86
+ return serializer_for_function(parsed.constructor)
@@ -0,0 +1,13 @@
1
+ from typing import Iterable, TypeVar, Union
2
+
3
+ T = TypeVar("T")
4
+
5
+
6
+ # pyright: reportGeneralTypeIssues=false
7
+ def ensure_iterable(value: Union[T, Iterable[T]]) -> Iterable[T]:
8
+ try:
9
+ iter(value)
10
+ # Now we now it is iterable
11
+ return value
12
+ except TypeError:
13
+ return [value]
@@ -0,0 +1,13 @@
1
+ import os
2
+
3
+ from ..marshmallow import EXCLUDE, RAISE
4
+ from ..marshmallow import Schema as MarshmallowSchema
5
+
6
+ MARSHMALLOW_UKNOWN_EXCLUDE = os.environ.get("STARKNET_PY_MARSHMALLOW_UKNOWN_EXCLUDE")
7
+
8
+
9
+ class Schema(MarshmallowSchema):
10
+ class Meta:
11
+ unknown = (
12
+ EXCLUDE if (MARSHMALLOW_UKNOWN_EXCLUDE or "").lower() == "true" else RAISE
13
+ )
@@ -0,0 +1,182 @@
1
+ from dataclasses import dataclass
2
+ from typing import Dict, List, Union, cast
3
+
4
+ from ...marshmallow import Schema, fields, post_load
5
+
6
+ from ..cairo.felt import encode_shortstring
7
+ from ..hash.selector import get_selector_from_name
8
+ from ..hash.utils import compute_hash_on_elements
9
+ from ..models.typed_data import StarkNetDomainDict, TypedDataDict
10
+
11
+
12
+ @dataclass(frozen=True)
13
+ class Parameter:
14
+ """
15
+ Dataclass representing a Parameter object
16
+ """
17
+
18
+ name: str
19
+ type: str
20
+
21
+
22
+ @dataclass(frozen=True)
23
+ class TypedData:
24
+ """
25
+ Dataclass representing a TypedData object
26
+ """
27
+
28
+ types: Dict[str, List[Parameter]]
29
+ primary_type: str
30
+ domain: StarkNetDomainDict
31
+ message: dict
32
+
33
+ @staticmethod
34
+ def from_dict(data: TypedDataDict) -> "TypedData":
35
+ """
36
+ Create TypedData dataclass from dictionary.
37
+
38
+ :param data: TypedData dictionary.
39
+ :return: TypedData dataclass instance.
40
+ """
41
+ return cast(TypedData, TypedDataSchema().load(data))
42
+
43
+ def _is_struct(self, type_name: str) -> bool:
44
+ return type_name in self.types
45
+
46
+ def _encode_value(self, type_name: str, value: Union[int, str, dict, list]) -> int:
47
+ if is_pointer(type_name) and isinstance(value, list):
48
+ type_name = strip_pointer(type_name)
49
+
50
+ if self._is_struct(type_name):
51
+ return compute_hash_on_elements(
52
+ [self.struct_hash(type_name, data) for data in value]
53
+ )
54
+ return compute_hash_on_elements([int(get_hex(val), 16) for val in value])
55
+
56
+ if self._is_struct(type_name) and isinstance(value, dict):
57
+ return self.struct_hash(type_name, value)
58
+
59
+ value = cast(Union[int, str], value)
60
+ return int(get_hex(value), 16)
61
+
62
+ def _encode_data(self, type_name: str, data: dict) -> List[int]:
63
+ values = []
64
+ for param in self.types[type_name]:
65
+ encoded_value = self._encode_value(param.type, data[param.name])
66
+ values.append(encoded_value)
67
+
68
+ return values
69
+
70
+ def _get_dependencies(self, type_name: str) -> List[str]:
71
+ if type_name not in self.types:
72
+ # type_name is a primitive type, has no dependencies
73
+ return []
74
+
75
+ dependencies = set()
76
+
77
+ def collect_deps(type_name: str) -> None:
78
+ for param in self.types[type_name]:
79
+ fixed_type = strip_pointer(param.type)
80
+ if fixed_type in self.types and fixed_type not in dependencies:
81
+ dependencies.add(fixed_type)
82
+ # recursive call
83
+ collect_deps(fixed_type)
84
+
85
+ # collect dependencies into a set
86
+ collect_deps(type_name)
87
+ return [type_name, *list(dependencies)]
88
+
89
+ def _encode_type(self, type_name: str) -> str:
90
+ primary, *dependencies = self._get_dependencies(type_name)
91
+ types = [primary, *sorted(dependencies)]
92
+
93
+ def make_dependency_str(dependency):
94
+ lst = [f"{t.name}:{t.type}" for t in self.types[dependency]]
95
+ return f"{dependency}({','.join(lst)})"
96
+
97
+ return "".join([make_dependency_str(x) for x in types])
98
+
99
+ def type_hash(self, type_name: str) -> int:
100
+ """
101
+ Calculate the hash of a type name.
102
+
103
+ :param type_name: Name of the type.
104
+ :return: Hash of the type name.
105
+ """
106
+ return get_selector_from_name(self._encode_type(type_name))
107
+
108
+ def struct_hash(self, type_name: str, data: dict) -> int:
109
+ """
110
+ Calculate the hash of a struct.
111
+
112
+ :param type_name: Name of the type.
113
+ :param data: Data defining the struct.
114
+ :return: Hash of the struct.
115
+ """
116
+ return compute_hash_on_elements(
117
+ [self.type_hash(type_name), *self._encode_data(type_name, data)]
118
+ )
119
+
120
+ def message_hash(self, account_address: int) -> int:
121
+ """
122
+ Calculate the hash of the message.
123
+
124
+ :param account_address: Address of an account.
125
+ :return: Hash of the message.
126
+ """
127
+ message = [
128
+ encode_shortstring("StarkNet Message"),
129
+ self.struct_hash("StarkNetDomain", cast(dict, self.domain)),
130
+ account_address,
131
+ self.struct_hash(self.primary_type, self.message),
132
+ ]
133
+
134
+ return compute_hash_on_elements(message)
135
+
136
+
137
+ def get_hex(value: Union[int, str]) -> str:
138
+ if isinstance(value, int):
139
+ return hex(value)
140
+ if value[:2] == "0x":
141
+ return value
142
+ if value.isnumeric():
143
+ return hex(int(value))
144
+ return hex(encode_shortstring(value))
145
+
146
+
147
+ def is_pointer(value: str) -> bool:
148
+ return len(value) > 0 and value[-1] == "*"
149
+
150
+
151
+ def strip_pointer(value: str) -> str:
152
+ if is_pointer(value):
153
+ return value[:-1]
154
+ return value
155
+
156
+
157
+ # pylint: disable=unused-argument
158
+ # pylint: disable=no-self-use
159
+
160
+
161
+ class ParameterSchema(Schema):
162
+ name = fields.String(data_key="name", required=True)
163
+ type = fields.String(data_key="type", required=True)
164
+
165
+ @post_load
166
+ def make_dataclass(self, data, **kwargs) -> Parameter:
167
+ return Parameter(**data)
168
+
169
+
170
+ class TypedDataSchema(Schema):
171
+ types = fields.Dict(
172
+ data_key="types",
173
+ keys=fields.Str(),
174
+ values=fields.List(fields.Nested(ParameterSchema())),
175
+ )
176
+ primary_type = fields.String(data_key="primaryType", required=True)
177
+ domain = fields.Dict(data_key="domain", required=True)
178
+ message = fields.Dict(data_key="message", required=True)
179
+
180
+ @post_load
181
+ def make_dataclass(self, data, **kwargs) -> TypedData:
182
+ return TypedData(**data)
@@ -0,0 +1,50 @@
1
+ from ...ecdsa.curves import Curve
2
+ from ...ecdsa.ellipticcurve import CurveFp, Point
3
+
4
+ from .signature import (
5
+ ALPHA,
6
+ BETA,
7
+ CONSTANT_POINTS,
8
+ EC_ORDER,
9
+ FIELD_PRIME,
10
+ N_ELEMENT_BITS_HASH,
11
+ SHIFT_POINT,
12
+ )
13
+ from .utils import from_bytes, to_bytes
14
+
15
+ curve_stark = CurveFp(FIELD_PRIME, ALPHA, BETA)
16
+ LOW_PART_BITS = 248
17
+ LOW_PART_MASK = 2**248 - 1
18
+ HASH_SHIFT_POINT = Point(curve_stark, SHIFT_POINT[0], SHIFT_POINT[1], EC_ORDER)
19
+ P_0 = Point(curve_stark, CONSTANT_POINTS[2][0], CONSTANT_POINTS[2][1], EC_ORDER)
20
+ P_1 = Point(curve_stark, CONSTANT_POINTS[2 + LOW_PART_BITS][0], CONSTANT_POINTS[2 + LOW_PART_BITS][1], EC_ORDER)
21
+ P_2 = Point(curve_stark, CONSTANT_POINTS[2 + N_ELEMENT_BITS_HASH][0], CONSTANT_POINTS[2 + N_ELEMENT_BITS_HASH][1], EC_ORDER)
22
+ P_3 = Point(curve_stark, CONSTANT_POINTS[2 + N_ELEMENT_BITS_HASH + LOW_PART_BITS][0], CONSTANT_POINTS[2 + N_ELEMENT_BITS_HASH + LOW_PART_BITS][1], EC_ORDER)
23
+
24
+ def process_single_element(element: int, p1, p2) -> Point:
25
+ assert 0 <= element < FIELD_PRIME, "Element integer value is out of range"
26
+
27
+ high_nibble = element >> LOW_PART_BITS
28
+ low_part = element & LOW_PART_MASK
29
+ return low_part * p1 + high_nibble * p2
30
+
31
+
32
+ def pedersen_hash(x: int, y: int) -> int:
33
+ """
34
+ Computes the Starkware version of the Pedersen hash of x and y.
35
+ The hash is defined by:
36
+ shift_point + x_low * P_0 + x_high * P1 + y_low * P2 + y_high * P3
37
+ where x_low is the 248 low bits of x, x_high is the 4 high bits of x and similarly for y.
38
+ shift_point, P_0, P_1, P_2, P_3 are constant points generated from the digits of pi.
39
+ """
40
+ return (
41
+ HASH_SHIFT_POINT + process_single_element(x, P_0, P_1) + process_single_element(y, P_2, P_3)
42
+ ).x()
43
+
44
+
45
+ def pedersen_hash_func(x: bytes, y: bytes) -> bytes:
46
+ """
47
+ A variant of 'pedersen_hash', where the elements and their resulting hash are in bytes.
48
+ """
49
+ assert len(x) == len(y) == 32, "Unexpected element length."
50
+ return to_bytes(pedersen_hash(*(from_bytes(element) for element in (x, y))))
@@ -0,0 +1,78 @@
1
+ ###############################################################################
2
+ # Copyright 2019 StarkWare Industries Ltd. #
3
+ # #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"). #
5
+ # You may not use this file except in compliance with the License. #
6
+ # You may obtain a copy of the License at #
7
+ # #
8
+ # https://www.starkware.co/open-source-license/ #
9
+ # #
10
+ # Unless required by applicable law or agreed to in writing, #
11
+ # software distributed under the License is distributed on an "AS IS" BASIS, #
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
13
+ # See the License for the specific language governing permissions #
14
+ # and limitations under the License. #
15
+ ###############################################################################
16
+
17
+
18
+ from typing import Tuple
19
+
20
+ from ...sympy.core.intfunc import igcdex
21
+
22
+ # A type that represents a point (x,y) on an elliptic curve.
23
+ ECPoint = Tuple[int, int]
24
+
25
+ def div_mod(n: int, m: int, p: int) -> int:
26
+ """
27
+ Finds a nonnegative integer 0 <= x < p such that (m * x) % p == n
28
+ """
29
+ a, b, c = igcdex(m, p)
30
+ assert c == 1
31
+ return (n * a) % p
32
+
33
+ def div_ceil(x, y):
34
+ assert isinstance(x, int) and isinstance(y, int)
35
+ return -((-x) // y)
36
+
37
+ def ec_add(point1: ECPoint, point2: ECPoint, p: int) -> ECPoint:
38
+ """
39
+ Gets two points on an elliptic curve mod p and returns their sum.
40
+ Assumes the points are given in affine form (x, y) and have different x coordinates.
41
+ """
42
+ assert (point1[0] - point2[0]) % p != 0
43
+ m = div_mod(point1[1] - point2[1], point1[0] - point2[0], p)
44
+ x = (m * m - point1[0] - point2[0]) % p
45
+ y = (m * (point1[0] - x) - point1[1]) % p
46
+ return x, y
47
+
48
+
49
+ def ec_neg(point: ECPoint, p: int) -> ECPoint:
50
+ """
51
+ Given a point (x,y) return (x, -y)
52
+ """
53
+ x, y = point
54
+ return (x, (-y) % p)
55
+
56
+
57
+ def ec_double(point: ECPoint, alpha: int, p: int) -> ECPoint:
58
+ """
59
+ Doubles a point on an elliptic curve with the equation y^2 = x^3 + alpha*x + beta mod p.
60
+ Assumes the point is given in affine form (x, y) and has y != 0.
61
+ """
62
+ assert point[1] % p != 0
63
+ m = div_mod(3 * point[0] * point[0] + alpha, 2 * point[1], p)
64
+ x = (m * m - 2 * point[0]) % p
65
+ y = (m * (point[0] - x) - point[1]) % p
66
+ return x, y
67
+
68
+
69
+ def ec_mult(m: int, point: ECPoint, alpha: int, p: int) -> ECPoint:
70
+ """
71
+ Multiplies by m a point on the elliptic curve with equation y^2 = x^3 + alpha*x + beta mod p.
72
+ Assumes the point is given in affine form (x, y) and that 0 < m < order(point).
73
+ """
74
+ if m == 1:
75
+ return point
76
+ if m % 2 == 0:
77
+ return ec_mult(m // 2, ec_double(point, alpha, p), alpha, p)
78
+ return ec_add(ec_mult(m - 1, point, alpha, p), point, p)