coinex-api 0.0.89__py3-none-any.whl → 0.0.110__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of coinex-api might be problematic. Click here for more details.
- coinex/ccxt/__init__.py +1 -1
- coinex/ccxt/async_support/__init__.py +1 -1
- coinex/ccxt/async_support/base/exchange.py +139 -10
- coinex/ccxt/async_support/base/throttler.py +1 -1
- coinex/ccxt/async_support/base/ws/cache.py +1 -0
- coinex/ccxt/async_support/base/ws/client.py +26 -4
- coinex/ccxt/async_support/coinex.py +2 -2
- coinex/ccxt/base/exchange.py +587 -91
- coinex/ccxt/base/types.py +11 -2
- coinex/ccxt/coinex.py +2 -2
- coinex/ccxt/pro/__init__.py +1 -1
- coinex/ccxt/pro/coinex.py +10 -7
- coinex/ccxt/static_dependencies/bip/__init__.py +6 -0
- coinex/ccxt/static_dependencies/bip/addr/P2PKH_addr.py +205 -0
- coinex/ccxt/static_dependencies/bip/addr/__init__.py +5 -0
- coinex/ccxt/static_dependencies/bip/addr/addr_dec_utils.py +125 -0
- coinex/ccxt/static_dependencies/bip/addr/addr_key_validator.py +162 -0
- coinex/ccxt/static_dependencies/bip/addr/iaddr_decoder.py +48 -0
- coinex/ccxt/static_dependencies/bip/addr/iaddr_encoder.py +50 -0
- coinex/ccxt/static_dependencies/bip/base58/__init__.py +3 -0
- coinex/ccxt/static_dependencies/bip/base58/base58.py +207 -0
- coinex/ccxt/static_dependencies/bip/base58/base58_ex.py +25 -0
- coinex/ccxt/static_dependencies/bip/base58/base58_xmr.py +155 -0
- coinex/ccxt/static_dependencies/bip/bech32/__init__.py +4 -0
- coinex/ccxt/static_dependencies/bip/bech32/bch_bech32.py +220 -0
- coinex/ccxt/static_dependencies/bip/bech32/bech32.py +235 -0
- coinex/ccxt/static_dependencies/bip/bech32/bech32_base.py +246 -0
- coinex/ccxt/static_dependencies/bip/bech32/bech32_ex.py +25 -0
- coinex/ccxt/static_dependencies/bip/bech32/segwit_bech32.py +173 -0
- coinex/ccxt/static_dependencies/bip/bip32/__init__.py +14 -0
- coinex/ccxt/static_dependencies/bip/bip32/base/__init__.py +3 -0
- coinex/ccxt/static_dependencies/bip/bip32/base/bip32_base.py +581 -0
- coinex/ccxt/static_dependencies/bip/bip32/base/ibip32_key_derivator.py +83 -0
- coinex/ccxt/static_dependencies/bip/bip32/base/ibip32_mst_key_generator.py +47 -0
- coinex/ccxt/static_dependencies/bip/bip32/bip32_const.py +35 -0
- coinex/ccxt/static_dependencies/bip/bip32/bip32_ex.py +29 -0
- coinex/ccxt/static_dependencies/bip/bip32/bip32_key_data.py +500 -0
- coinex/ccxt/static_dependencies/bip/bip32/bip32_key_net_ver.py +83 -0
- coinex/ccxt/static_dependencies/bip/bip32/bip32_key_ser.py +294 -0
- coinex/ccxt/static_dependencies/bip/bip32/bip32_keys.py +457 -0
- coinex/ccxt/static_dependencies/bip/bip32/bip32_path.py +247 -0
- coinex/ccxt/static_dependencies/bip/bip32/bip32_utils.py +72 -0
- coinex/ccxt/static_dependencies/bip/bip32/kholaw/__init__.py +4 -0
- coinex/ccxt/static_dependencies/bip/bip32/kholaw/bip32_kholaw_ed25519.py +82 -0
- coinex/ccxt/static_dependencies/bip/bip32/kholaw/bip32_kholaw_ed25519_key_derivator.py +118 -0
- coinex/ccxt/static_dependencies/bip/bip32/kholaw/bip32_kholaw_key_derivator_base.py +204 -0
- coinex/ccxt/static_dependencies/bip/bip32/kholaw/bip32_kholaw_mst_key_generator.py +119 -0
- coinex/ccxt/static_dependencies/bip/bip32/slip10/__init__.py +1 -0
- coinex/ccxt/static_dependencies/bip/bip32/slip10/bip32_slip10_key_derivator.py +200 -0
- coinex/ccxt/static_dependencies/bip/bip32/slip10/bip32_slip10_mst_key_generator.py +168 -0
- coinex/ccxt/static_dependencies/bip/bip32/slip10/bip32_slip10_secp256k1.py +82 -0
- coinex/ccxt/static_dependencies/bip/bip44/__init__.py +1 -0
- coinex/ccxt/static_dependencies/bip/bip44/bip44.py +265 -0
- coinex/ccxt/static_dependencies/bip/bip44_base/__init__.py +3 -0
- coinex/ccxt/static_dependencies/bip/bip44_base/bip44_base.py +624 -0
- coinex/ccxt/static_dependencies/bip/bip44_base/bip44_base_ex.py +25 -0
- coinex/ccxt/static_dependencies/bip/bip44_base/bip44_keys.py +225 -0
- coinex/ccxt/static_dependencies/bip/coin_conf/__init__.py +2 -0
- coinex/ccxt/static_dependencies/bip/coin_conf/coin_conf.py +68 -0
- coinex/ccxt/static_dependencies/bip/coin_conf/coins_conf.py +890 -0
- coinex/ccxt/static_dependencies/bip/conf/__init__.py +0 -0
- coinex/ccxt/static_dependencies/bip/conf/bip44/__init__.py +3 -0
- coinex/ccxt/static_dependencies/bip/conf/bip44/bip44_coins.py +126 -0
- coinex/ccxt/static_dependencies/bip/conf/bip44/bip44_conf.py +1360 -0
- coinex/ccxt/static_dependencies/bip/conf/bip44/bip44_conf_getter.py +153 -0
- coinex/ccxt/static_dependencies/bip/conf/bip49/__init__.py +3 -0
- coinex/ccxt/static_dependencies/bip/conf/bip49/bip49_coins.py +53 -0
- coinex/ccxt/static_dependencies/bip/conf/bip49/bip49_conf.py +366 -0
- coinex/ccxt/static_dependencies/bip/conf/bip49/bip49_conf_getter.py +80 -0
- coinex/ccxt/static_dependencies/bip/conf/bip84/__init__.py +3 -0
- coinex/ccxt/static_dependencies/bip/conf/bip84/bip84_coins.py +39 -0
- coinex/ccxt/static_dependencies/bip/conf/bip84/bip84_conf.py +113 -0
- coinex/ccxt/static_dependencies/bip/conf/bip84/bip84_conf_getter.py +66 -0
- coinex/ccxt/static_dependencies/bip/conf/bip86/__init__.py +3 -0
- coinex/ccxt/static_dependencies/bip/conf/bip86/bip86_coins.py +37 -0
- coinex/ccxt/static_dependencies/bip/conf/bip86/bip86_conf.py +83 -0
- coinex/ccxt/static_dependencies/bip/conf/bip86/bip86_conf_getter.py +64 -0
- coinex/ccxt/static_dependencies/bip/conf/common/__init__.py +8 -0
- coinex/ccxt/static_dependencies/bip/conf/common/atom_addr.py +104 -0
- coinex/ccxt/static_dependencies/bip/conf/common/bip_bitcoin_cash_conf.py +106 -0
- coinex/ccxt/static_dependencies/bip/conf/common/bip_coin_conf.py +217 -0
- coinex/ccxt/static_dependencies/bip/conf/common/bip_coins.py +28 -0
- coinex/ccxt/static_dependencies/bip/conf/common/bip_conf_const.py +30 -0
- coinex/ccxt/static_dependencies/bip/conf/common/bip_litecoin_conf.py +121 -0
- coinex/ccxt/static_dependencies/bip/ecc/__init__.py +42 -0
- coinex/ccxt/static_dependencies/bip/ecc/common/__init__.py +0 -0
- coinex/ccxt/static_dependencies/bip/ecc/common/dummy_point.py +219 -0
- coinex/ccxt/static_dependencies/bip/ecc/common/ikeys.py +263 -0
- coinex/ccxt/static_dependencies/bip/ecc/common/ipoint.py +190 -0
- coinex/ccxt/static_dependencies/bip/ecc/conf.py +28 -0
- coinex/ccxt/static_dependencies/bip/ecc/curve/__init__.py +0 -0
- coinex/ccxt/static_dependencies/bip/ecc/curve/elliptic_curve.py +121 -0
- coinex/ccxt/static_dependencies/bip/ecc/curve/elliptic_curve_getter.py +74 -0
- coinex/ccxt/static_dependencies/bip/ecc/curve/elliptic_curve_types.py +37 -0
- coinex/ccxt/static_dependencies/bip/ecc/ecdsa/__init__.py +0 -0
- coinex/ccxt/static_dependencies/bip/ecc/ecdsa/ecdsa_keys.py +36 -0
- coinex/ccxt/static_dependencies/bip/ecc/secp256k1/__init__.py +0 -0
- coinex/ccxt/static_dependencies/bip/ecc/secp256k1/secp256k1.py +36 -0
- coinex/ccxt/static_dependencies/bip/ecc/secp256k1/secp256k1_const.py +59 -0
- coinex/ccxt/static_dependencies/bip/ecc/secp256k1/secp256k1_keys_ecdsa.py +248 -0
- coinex/ccxt/static_dependencies/bip/ecc/secp256k1/secp256k1_point_ecdsa.py +234 -0
- coinex/ccxt/static_dependencies/bip/slip/__init__.py +0 -0
- coinex/ccxt/static_dependencies/bip/slip/slip173/__init__.py +1 -0
- coinex/ccxt/static_dependencies/bip/slip/slip173/slip173.py +60 -0
- coinex/ccxt/static_dependencies/bip/slip/slip32/__init__.py +4 -0
- coinex/ccxt/static_dependencies/bip/slip/slip32/slip32.py +322 -0
- coinex/ccxt/static_dependencies/bip/slip/slip32/slip32_key_net_ver.py +62 -0
- coinex/ccxt/static_dependencies/bip/slip/slip44/__init__.py +1 -0
- coinex/ccxt/static_dependencies/bip/slip/slip44/slip44.py +81 -0
- coinex/ccxt/static_dependencies/bip/utils/__init__.py +0 -0
- coinex/ccxt/static_dependencies/bip/utils/conf/__init__.py +1 -0
- coinex/ccxt/static_dependencies/bip/utils/conf/coin_names.py +59 -0
- coinex/ccxt/static_dependencies/bip/utils/crypto/__init__.py +10 -0
- coinex/ccxt/static_dependencies/bip/utils/crypto/aes_ecb.py +152 -0
- coinex/ccxt/static_dependencies/bip/utils/crypto/blake2.py +191 -0
- coinex/ccxt/static_dependencies/bip/utils/crypto/chacha20_poly1305.py +101 -0
- coinex/ccxt/static_dependencies/bip/utils/crypto/hash160.py +57 -0
- coinex/ccxt/static_dependencies/bip/utils/crypto/hmac.py +118 -0
- coinex/ccxt/static_dependencies/bip/utils/crypto/pbkdf2.py +66 -0
- coinex/ccxt/static_dependencies/bip/utils/crypto/ripemd.py +58 -0
- coinex/ccxt/static_dependencies/bip/utils/crypto/scrypt.py +66 -0
- coinex/ccxt/static_dependencies/bip/utils/crypto/sha2.py +182 -0
- coinex/ccxt/static_dependencies/bip/utils/crypto/sha3.py +99 -0
- coinex/ccxt/static_dependencies/bip/utils/misc/__init__.py +7 -0
- coinex/ccxt/static_dependencies/bip/utils/misc/algo.py +108 -0
- coinex/ccxt/static_dependencies/bip/utils/misc/base32.py +151 -0
- coinex/ccxt/static_dependencies/bip/utils/misc/bit.py +115 -0
- coinex/ccxt/static_dependencies/bip/utils/misc/bytes.py +200 -0
- coinex/ccxt/static_dependencies/bip/utils/misc/data_bytes.py +181 -0
- coinex/ccxt/static_dependencies/bip/utils/misc/integer.py +97 -0
- coinex/ccxt/static_dependencies/bip/utils/misc/string.py +54 -0
- coinex/ccxt/static_dependencies/bip/utils/typing/__init__.py +1 -0
- coinex/ccxt/static_dependencies/bip/utils/typing/literal.py +27 -0
- coinex/ccxt/static_dependencies/bip/wif/__init__.py +1 -0
- coinex/ccxt/static_dependencies/bip/wif/wif.py +144 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/amino/amino_pb2.py +31 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/cosmos/base/v1beta1/coin_pb2.py +47 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/cosmos/crypto/multisig/keys_pb2.py +33 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/cosmos/crypto/multisig/v1beta1/multisig_pb2.py +33 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/cosmos/crypto/secp256k1/keys_pb2.py +34 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/cosmos/msg/v1/msg_pb2.py +27 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/cosmos/tx/signing/v1beta1/signing_pb2.py +38 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/cosmos/tx/v1beta1/tx_pb2.py +75 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/cosmos_proto/cosmos_pb2.py +36 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/accountplus/accountplus_pb2.py +31 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/accountplus/genesis_pb2.py +40 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/accountplus/models_pb2.py +26 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/accountplus/params_pb2.py +29 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/accountplus/query_pb2.py +57 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/accountplus/tx_pb2.py +51 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/block_rate_limit_config_pb2.py +37 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/clob_pair_pb2.py +41 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/equity_tier_limit_config_pb2.py +35 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/finalize_block_pb2.py +27 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/liquidations_config_pb2.py +39 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/liquidations_pb2.py +38 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/matches_pb2.py +55 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/mev_pb2.py +49 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/operation_pb2.py +32 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/order_pb2.py +86 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/order_removals_pb2.py +32 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/process_proposer_matches_events_pb2.py +42 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/query_pb2.py +124 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/streaming_pb2.py +29 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/clob/tx_pb2.py +117 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/sending/genesis_pb2.py +26 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/sending/query_pb2.py +26 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/sending/transfer_pb2.py +61 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/sending/tx_pb2.py +37 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/subaccounts/asset_position_pb2.py +29 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/subaccounts/genesis_pb2.py +30 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/subaccounts/perpetual_position_pb2.py +33 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/subaccounts/query_pb2.py +63 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/subaccounts/streaming_pb2.py +31 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/dydxprotocol/subaccounts/subaccount_pb2.py +33 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/gogoproto/gogo_pb2.py +102 -0
- coinex/ccxt/static_dependencies/dydx_v4_client/registry.py +38 -0
- coinex/ccxt/static_dependencies/ecdsa/ellipticcurve.py +842 -0
- coinex/ccxt/static_dependencies/ecdsa/keys.py +15 -4
- coinex/ccxt/static_dependencies/mnemonic/__init__.py +4 -0
- coinex/ccxt/static_dependencies/mnemonic/mnemonic.py +282 -0
- coinex/ccxt/static_dependencies/mnemonic/py.typed +1 -0
- coinex/ccxt/static_dependencies/mnemonic/wordlist/chinese_simplified.txt +2048 -0
- coinex/ccxt/static_dependencies/mnemonic/wordlist/chinese_traditional.txt +2048 -0
- coinex/ccxt/static_dependencies/mnemonic/wordlist/czech.txt +2048 -0
- coinex/ccxt/static_dependencies/mnemonic/wordlist/english.txt +2048 -0
- coinex/ccxt/static_dependencies/mnemonic/wordlist/french.txt +2048 -0
- coinex/ccxt/static_dependencies/mnemonic/wordlist/italian.txt +2048 -0
- coinex/ccxt/static_dependencies/mnemonic/wordlist/japanese.txt +2048 -0
- coinex/ccxt/static_dependencies/mnemonic/wordlist/korean.txt +2048 -0
- coinex/ccxt/static_dependencies/mnemonic/wordlist/portuguese.txt +2048 -0
- coinex/ccxt/static_dependencies/mnemonic/wordlist/russian.txt +2048 -0
- coinex/ccxt/static_dependencies/mnemonic/wordlist/spanish.txt +2048 -0
- coinex/ccxt/static_dependencies/mnemonic/wordlist/turkish.txt +2048 -0
- {coinex_api-0.0.89.dist-info → coinex_api-0.0.110.dist-info}/METADATA +3 -3
- {coinex_api-0.0.89.dist-info → coinex_api-0.0.110.dist-info}/RECORD +197 -17
- {coinex_api-0.0.89.dist-info → coinex_api-0.0.110.dist-info}/WHEEL +1 -1
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# Copyright (c) 2021 Emanuele Bellocchia
|
|
2
|
+
#
|
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
# furnished to do so, subject to the following conditions:
|
|
9
|
+
#
|
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
|
11
|
+
# all copies or substantial portions of the Software.
|
|
12
|
+
#
|
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
# THE SOFTWARE.
|
|
20
|
+
|
|
21
|
+
"""Module with some bits utility functions."""
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class BitUtils:
|
|
25
|
+
"""Class container for bit utility functions."""
|
|
26
|
+
|
|
27
|
+
@staticmethod
|
|
28
|
+
def IsBitSet(value: int,
|
|
29
|
+
bit_num: int) -> bool:
|
|
30
|
+
"""
|
|
31
|
+
Get if the specified bit is set.
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
value (int) : Value
|
|
35
|
+
bit_num (int): Bit number to check
|
|
36
|
+
|
|
37
|
+
Returns:
|
|
38
|
+
bool: True if bit is set, false otherwise
|
|
39
|
+
"""
|
|
40
|
+
return (value & (1 << bit_num)) != 0
|
|
41
|
+
|
|
42
|
+
@staticmethod
|
|
43
|
+
def AreBitsSet(value: int,
|
|
44
|
+
bit_mask: int) -> bool:
|
|
45
|
+
"""
|
|
46
|
+
Get if the specified bits are set.
|
|
47
|
+
|
|
48
|
+
Args:
|
|
49
|
+
value (int) : Value
|
|
50
|
+
bit_mask (int): Bit mask to check
|
|
51
|
+
|
|
52
|
+
Returns:
|
|
53
|
+
bool: True if bit is set, false otherwise
|
|
54
|
+
"""
|
|
55
|
+
return (value & bit_mask) != 0
|
|
56
|
+
|
|
57
|
+
@staticmethod
|
|
58
|
+
def SetBit(value: int,
|
|
59
|
+
bit_num: int) -> int:
|
|
60
|
+
"""
|
|
61
|
+
Set the specified bit.
|
|
62
|
+
|
|
63
|
+
Args:
|
|
64
|
+
value (int) : Value
|
|
65
|
+
bit_num (int): Bit number to set
|
|
66
|
+
|
|
67
|
+
Returns:
|
|
68
|
+
int: Value with the specified bit set
|
|
69
|
+
"""
|
|
70
|
+
return value | (1 << bit_num)
|
|
71
|
+
|
|
72
|
+
@staticmethod
|
|
73
|
+
def SetBits(value: int,
|
|
74
|
+
bit_mask: int) -> int:
|
|
75
|
+
"""
|
|
76
|
+
Set the specified bits.
|
|
77
|
+
|
|
78
|
+
Args:
|
|
79
|
+
value (int) : Value
|
|
80
|
+
bit_mask (int): Bit mask to set
|
|
81
|
+
|
|
82
|
+
Returns:
|
|
83
|
+
int: Value with the specified bit set
|
|
84
|
+
"""
|
|
85
|
+
return value | bit_mask
|
|
86
|
+
|
|
87
|
+
@staticmethod
|
|
88
|
+
def ResetBit(value: int,
|
|
89
|
+
bit_num: int) -> int:
|
|
90
|
+
"""
|
|
91
|
+
Reset the specified bit.
|
|
92
|
+
|
|
93
|
+
Args:
|
|
94
|
+
value (int) : Value
|
|
95
|
+
bit_num (int): Bit number to reset
|
|
96
|
+
|
|
97
|
+
Returns:
|
|
98
|
+
int: Value with the specified bit reset
|
|
99
|
+
"""
|
|
100
|
+
return value & ~(1 << bit_num)
|
|
101
|
+
|
|
102
|
+
@staticmethod
|
|
103
|
+
def ResetBits(value: int,
|
|
104
|
+
bit_mask: int) -> int:
|
|
105
|
+
"""
|
|
106
|
+
Reset the specified bits.
|
|
107
|
+
|
|
108
|
+
Args:
|
|
109
|
+
value (int) : Value
|
|
110
|
+
bit_mask (int): Bit mask to reset
|
|
111
|
+
|
|
112
|
+
Returns:
|
|
113
|
+
int: Value with the specified bit reset
|
|
114
|
+
"""
|
|
115
|
+
return value & ~bit_mask
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
# Copyright (c) 2021 Emanuele Bellocchia
|
|
2
|
+
#
|
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
# furnished to do so, subject to the following conditions:
|
|
9
|
+
#
|
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
|
11
|
+
# all copies or substantial portions of the Software.
|
|
12
|
+
#
|
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
# THE SOFTWARE.
|
|
20
|
+
|
|
21
|
+
"""Module with some bytes utility functions."""
|
|
22
|
+
|
|
23
|
+
# Imports
|
|
24
|
+
import binascii
|
|
25
|
+
from typing import List, Union
|
|
26
|
+
|
|
27
|
+
from .algo import AlgoUtils
|
|
28
|
+
from .integer import IntegerUtils
|
|
29
|
+
from ..typing import Literal
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class BytesUtils:
|
|
33
|
+
"""Class container for bytes utility functions."""
|
|
34
|
+
|
|
35
|
+
@staticmethod
|
|
36
|
+
def Reverse(data_bytes: bytes) -> bytes:
|
|
37
|
+
"""
|
|
38
|
+
Reverse the specified bytes.
|
|
39
|
+
|
|
40
|
+
Args:
|
|
41
|
+
data_bytes (bytes): Data bytes
|
|
42
|
+
|
|
43
|
+
Returns:
|
|
44
|
+
bytes: Original bytes in the reverse order
|
|
45
|
+
"""
|
|
46
|
+
tmp = bytearray(data_bytes)
|
|
47
|
+
tmp.reverse()
|
|
48
|
+
return bytes(tmp)
|
|
49
|
+
|
|
50
|
+
@staticmethod
|
|
51
|
+
def Xor(data_bytes_1: bytes,
|
|
52
|
+
data_bytes_2: bytes) -> bytes:
|
|
53
|
+
"""
|
|
54
|
+
XOR the specified bytes.
|
|
55
|
+
|
|
56
|
+
Args:
|
|
57
|
+
data_bytes_1 (bytes): Data bytes 1
|
|
58
|
+
data_bytes_2 (bytes): Data bytes 2
|
|
59
|
+
|
|
60
|
+
Returns:
|
|
61
|
+
bytes: XORed bytes
|
|
62
|
+
"""
|
|
63
|
+
return bytes(
|
|
64
|
+
[b1 ^ b2 for b1, b2 in zip(data_bytes_1, data_bytes_2)]
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
@staticmethod
|
|
68
|
+
def AddNoCarry(data_bytes_1: bytes,
|
|
69
|
+
data_bytes_2: bytes) -> bytes:
|
|
70
|
+
"""
|
|
71
|
+
Add the specified bytes (byte-by-byte, no carry).
|
|
72
|
+
|
|
73
|
+
Args:
|
|
74
|
+
data_bytes_1 (bytes): Data bytes 1
|
|
75
|
+
data_bytes_2 (bytes): Data bytes 2
|
|
76
|
+
|
|
77
|
+
Returns:
|
|
78
|
+
bytes: XORed bytes
|
|
79
|
+
"""
|
|
80
|
+
return bytes(
|
|
81
|
+
[(b1 + b2) & 0xFF for b1, b2 in zip(data_bytes_1, data_bytes_2)]
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
@staticmethod
|
|
85
|
+
def MultiplyScalarNoCarry(data_bytes: bytes,
|
|
86
|
+
scalar: int) -> bytes:
|
|
87
|
+
"""
|
|
88
|
+
Multiply the specified bytes with the specified scalar (byte-by-byte, no carry).
|
|
89
|
+
|
|
90
|
+
Args:
|
|
91
|
+
data_bytes (bytes): Data bytes
|
|
92
|
+
scalar (int) : Scalar
|
|
93
|
+
|
|
94
|
+
Returns:
|
|
95
|
+
bytes: XORed bytes
|
|
96
|
+
"""
|
|
97
|
+
return bytes(
|
|
98
|
+
[(b * scalar) & 0xFF for b in data_bytes]
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
@staticmethod
|
|
102
|
+
def ToBinaryStr(data_bytes: bytes,
|
|
103
|
+
zero_pad_bit_len: int = 0) -> str:
|
|
104
|
+
"""
|
|
105
|
+
Convert the specified bytes to a binary string.
|
|
106
|
+
|
|
107
|
+
Args:
|
|
108
|
+
data_bytes (bytes) : Data bytes
|
|
109
|
+
zero_pad_bit_len (int, optional): Zero pad length in bits, 0 if not specified
|
|
110
|
+
|
|
111
|
+
Returns:
|
|
112
|
+
str: Binary string
|
|
113
|
+
"""
|
|
114
|
+
return IntegerUtils.ToBinaryStr(BytesUtils.ToInteger(data_bytes), zero_pad_bit_len)
|
|
115
|
+
|
|
116
|
+
@staticmethod
|
|
117
|
+
def ToInteger(data_bytes: bytes,
|
|
118
|
+
endianness: Literal["little", "big"] = "big",
|
|
119
|
+
signed: bool = False) -> int:
|
|
120
|
+
"""
|
|
121
|
+
Convert the specified bytes to integer.
|
|
122
|
+
|
|
123
|
+
Args:
|
|
124
|
+
data_bytes (bytes) : Data bytes
|
|
125
|
+
endianness ("big" or "little", optional): Endianness (default: big)
|
|
126
|
+
signed (bool, optional) : True if signed, false otherwise (default: false)
|
|
127
|
+
|
|
128
|
+
Returns:
|
|
129
|
+
int: Integer representation
|
|
130
|
+
"""
|
|
131
|
+
return int.from_bytes(data_bytes, byteorder=endianness, signed=signed)
|
|
132
|
+
|
|
133
|
+
@staticmethod
|
|
134
|
+
def FromBinaryStr(data: Union[bytes, str],
|
|
135
|
+
zero_pad_byte_len: int = 0) -> bytes:
|
|
136
|
+
"""
|
|
137
|
+
Convert the specified binary string to bytes.
|
|
138
|
+
|
|
139
|
+
Args:
|
|
140
|
+
data (str or bytes) : Data
|
|
141
|
+
zero_pad_byte_len (int, optional): Zero pad length in bytes, 0 if not specified
|
|
142
|
+
|
|
143
|
+
Returns:
|
|
144
|
+
bytes: Bytes representation
|
|
145
|
+
"""
|
|
146
|
+
return binascii.unhexlify(hex(IntegerUtils.FromBinaryStr(data))[2:].zfill(zero_pad_byte_len))
|
|
147
|
+
|
|
148
|
+
@staticmethod
|
|
149
|
+
def ToHexString(data_bytes: bytes,
|
|
150
|
+
encoding: str = "utf-8") -> str:
|
|
151
|
+
"""
|
|
152
|
+
Convert bytes to hex string.
|
|
153
|
+
|
|
154
|
+
Args:
|
|
155
|
+
data_bytes (bytes) : Data bytes
|
|
156
|
+
encoding (str, optional): Encoding type, utf-8 by default
|
|
157
|
+
|
|
158
|
+
Returns:
|
|
159
|
+
str: Bytes converted to hex string
|
|
160
|
+
"""
|
|
161
|
+
return AlgoUtils.Decode(binascii.hexlify(data_bytes), encoding)
|
|
162
|
+
|
|
163
|
+
@staticmethod
|
|
164
|
+
def FromHexString(data: Union[bytes, str]) -> bytes:
|
|
165
|
+
"""
|
|
166
|
+
Convert hex string to bytes.
|
|
167
|
+
|
|
168
|
+
Args:
|
|
169
|
+
data (str or bytes): Data bytes
|
|
170
|
+
|
|
171
|
+
Returns
|
|
172
|
+
bytes: Hex string converted to bytes
|
|
173
|
+
"""
|
|
174
|
+
return binascii.unhexlify(AlgoUtils.Encode(data))
|
|
175
|
+
|
|
176
|
+
@staticmethod
|
|
177
|
+
def FromList(data_list: List[int]) -> bytes:
|
|
178
|
+
"""
|
|
179
|
+
Convert the specified list of integers to bytes.
|
|
180
|
+
|
|
181
|
+
Args:
|
|
182
|
+
data_list (list[int]): List of integers
|
|
183
|
+
|
|
184
|
+
Returns:
|
|
185
|
+
bytes: Bytes representation
|
|
186
|
+
"""
|
|
187
|
+
return bytes(data_list)
|
|
188
|
+
|
|
189
|
+
@staticmethod
|
|
190
|
+
def ToList(data_bytes: bytes) -> List[int]:
|
|
191
|
+
"""
|
|
192
|
+
Convert the specified bytes to a list of integers.
|
|
193
|
+
|
|
194
|
+
Args:
|
|
195
|
+
data_bytes (bytes): Data bytes
|
|
196
|
+
|
|
197
|
+
Returns:
|
|
198
|
+
list[int]: List of integers
|
|
199
|
+
"""
|
|
200
|
+
return list(data_bytes)
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
# Copyright (c) 2021 Emanuele Bellocchia
|
|
2
|
+
#
|
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
# furnished to do so, subject to the following conditions:
|
|
9
|
+
#
|
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
|
11
|
+
# all copies or substantial portions of the Software.
|
|
12
|
+
#
|
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
# THE SOFTWARE.
|
|
20
|
+
|
|
21
|
+
"""Module with helper class for data bytes."""
|
|
22
|
+
|
|
23
|
+
# Imports
|
|
24
|
+
from typing import Iterator
|
|
25
|
+
|
|
26
|
+
from .bytes import BytesUtils
|
|
27
|
+
from ..typing import Literal
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class DataBytes:
|
|
31
|
+
"""
|
|
32
|
+
Data bytes class.
|
|
33
|
+
It allows to get bytes in different formats.
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
m_data_bytes: bytes
|
|
37
|
+
|
|
38
|
+
def __init__(self,
|
|
39
|
+
data_bytes: bytes) -> None:
|
|
40
|
+
"""
|
|
41
|
+
Construct class.
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
data_bytes (bytes): Data bytes
|
|
45
|
+
"""
|
|
46
|
+
self.m_data_bytes = data_bytes
|
|
47
|
+
|
|
48
|
+
def Length(self) -> int:
|
|
49
|
+
"""
|
|
50
|
+
Get length in bytes.
|
|
51
|
+
|
|
52
|
+
Returns:
|
|
53
|
+
int: Length in bytes
|
|
54
|
+
"""
|
|
55
|
+
return len(self.m_data_bytes)
|
|
56
|
+
|
|
57
|
+
def Size(self) -> int:
|
|
58
|
+
"""
|
|
59
|
+
Get length in bytes (same of Length()).
|
|
60
|
+
|
|
61
|
+
Returns:
|
|
62
|
+
int: Length in bytes
|
|
63
|
+
"""
|
|
64
|
+
return self.Length()
|
|
65
|
+
|
|
66
|
+
def ToBytes(self) -> bytes:
|
|
67
|
+
"""
|
|
68
|
+
Get data bytes.
|
|
69
|
+
|
|
70
|
+
Returns:
|
|
71
|
+
bytes: Data bytes
|
|
72
|
+
"""
|
|
73
|
+
return self.m_data_bytes
|
|
74
|
+
|
|
75
|
+
def ToHex(self) -> str:
|
|
76
|
+
"""
|
|
77
|
+
Get data bytes in hex format.
|
|
78
|
+
|
|
79
|
+
Returns:
|
|
80
|
+
str: Data bytes in hex format
|
|
81
|
+
"""
|
|
82
|
+
return BytesUtils.ToHexString(self.m_data_bytes)
|
|
83
|
+
|
|
84
|
+
def ToInt(self,
|
|
85
|
+
endianness: Literal["little", "big"] = "big") -> int:
|
|
86
|
+
"""
|
|
87
|
+
Get data bytes as an integer.
|
|
88
|
+
|
|
89
|
+
Args:
|
|
90
|
+
endianness ("big" or "little", optional): Endianness (default: big)
|
|
91
|
+
|
|
92
|
+
Returns:
|
|
93
|
+
int: Data bytes as an integer
|
|
94
|
+
"""
|
|
95
|
+
return BytesUtils.ToInteger(self.m_data_bytes, endianness)
|
|
96
|
+
|
|
97
|
+
def __len__(self) -> int:
|
|
98
|
+
"""
|
|
99
|
+
Get length in bytes.
|
|
100
|
+
|
|
101
|
+
Returns:
|
|
102
|
+
int: Length in bytes
|
|
103
|
+
"""
|
|
104
|
+
return self.Length()
|
|
105
|
+
|
|
106
|
+
def __bytes__(self) -> bytes:
|
|
107
|
+
"""
|
|
108
|
+
Get data bytes.
|
|
109
|
+
|
|
110
|
+
Returns:
|
|
111
|
+
bytes: Data bytes
|
|
112
|
+
"""
|
|
113
|
+
return self.ToBytes()
|
|
114
|
+
|
|
115
|
+
def __int__(self) -> int:
|
|
116
|
+
"""
|
|
117
|
+
Get data bytes as integer.
|
|
118
|
+
|
|
119
|
+
Returns:
|
|
120
|
+
bytes: Data bytes as integer
|
|
121
|
+
"""
|
|
122
|
+
return self.ToInt()
|
|
123
|
+
|
|
124
|
+
def __repr__(self) -> str:
|
|
125
|
+
"""
|
|
126
|
+
Get data bytes representation.
|
|
127
|
+
|
|
128
|
+
Returns:
|
|
129
|
+
str: Data bytes representation
|
|
130
|
+
"""
|
|
131
|
+
return self.ToHex()
|
|
132
|
+
|
|
133
|
+
def __getitem__(self,
|
|
134
|
+
idx: int) -> int:
|
|
135
|
+
"""
|
|
136
|
+
Get the element with the specified index.
|
|
137
|
+
|
|
138
|
+
Args:
|
|
139
|
+
idx (int): Index
|
|
140
|
+
|
|
141
|
+
Returns:
|
|
142
|
+
int: Element
|
|
143
|
+
|
|
144
|
+
Raises:
|
|
145
|
+
IndexError: If the index is not valid
|
|
146
|
+
"""
|
|
147
|
+
return self.m_data_bytes[idx]
|
|
148
|
+
|
|
149
|
+
def __iter__(self) -> Iterator[int]:
|
|
150
|
+
"""
|
|
151
|
+
Get the iterator to the current element.
|
|
152
|
+
|
|
153
|
+
Returns:
|
|
154
|
+
Iterator object: Iterator to the current element
|
|
155
|
+
"""
|
|
156
|
+
yield from self.m_data_bytes
|
|
157
|
+
|
|
158
|
+
def __eq__(self,
|
|
159
|
+
other: object) -> bool:
|
|
160
|
+
"""
|
|
161
|
+
Equality operator.
|
|
162
|
+
|
|
163
|
+
Args:
|
|
164
|
+
other (bytes, str, int or DataBytes object): Other object to compare
|
|
165
|
+
|
|
166
|
+
Returns:
|
|
167
|
+
bool: True if equal false otherwise
|
|
168
|
+
|
|
169
|
+
Raises:
|
|
170
|
+
TypeError: If the other object is not of the correct type
|
|
171
|
+
"""
|
|
172
|
+
if not isinstance(other, (bytes, int, str, DataBytes)):
|
|
173
|
+
raise TypeError(f"Invalid type for checking equality ({type(other)})")
|
|
174
|
+
|
|
175
|
+
if isinstance(other, bytes):
|
|
176
|
+
return other == bytes(self)
|
|
177
|
+
if isinstance(other, int):
|
|
178
|
+
return other == int(self)
|
|
179
|
+
if isinstance(other, str):
|
|
180
|
+
return other == str(self)
|
|
181
|
+
return bytes(other) == bytes(self)
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Copyright (c) 2021 Emanuele Bellocchia
|
|
2
|
+
#
|
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
# furnished to do so, subject to the following conditions:
|
|
9
|
+
#
|
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
|
11
|
+
# all copies or substantial portions of the Software.
|
|
12
|
+
#
|
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
# THE SOFTWARE.
|
|
20
|
+
|
|
21
|
+
"""Module with some integer utility functions."""
|
|
22
|
+
|
|
23
|
+
# Imports
|
|
24
|
+
from typing import Optional, Union
|
|
25
|
+
|
|
26
|
+
from .algo import AlgoUtils
|
|
27
|
+
from ..typing import Literal
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class IntegerUtils:
|
|
31
|
+
"""Class container for integer utility functions."""
|
|
32
|
+
|
|
33
|
+
@staticmethod
|
|
34
|
+
def GetBytesNumber(data_int: int) -> int:
|
|
35
|
+
"""
|
|
36
|
+
Get the number of bytes of the specified integer.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
data_int (int): Data integer
|
|
40
|
+
|
|
41
|
+
Returns:
|
|
42
|
+
int: Number of bytes
|
|
43
|
+
"""
|
|
44
|
+
return ((data_int.bit_length() if data_int > 0 else 1) + 7) // 8
|
|
45
|
+
|
|
46
|
+
@staticmethod
|
|
47
|
+
def ToBytes(data_int: int,
|
|
48
|
+
bytes_num: Optional[int] = None,
|
|
49
|
+
endianness: Literal["little", "big"] = "big",
|
|
50
|
+
signed: bool = False) -> bytes:
|
|
51
|
+
"""
|
|
52
|
+
Convert integer to bytes.
|
|
53
|
+
|
|
54
|
+
Args:
|
|
55
|
+
data_int (int) : Data integer
|
|
56
|
+
bytes_num (int, optional) : Number of bytes, automatic if None
|
|
57
|
+
endianness ("big" or "little", optional): Endianness (default: big)
|
|
58
|
+
signed (bool, optional) : True if signed, false otherwise (default: false)
|
|
59
|
+
|
|
60
|
+
Returns:
|
|
61
|
+
bytes: Bytes representation
|
|
62
|
+
"""
|
|
63
|
+
|
|
64
|
+
# In case gmpy is used
|
|
65
|
+
if data_int.__class__.__name__ == "mpz":
|
|
66
|
+
data_int = int(data_int)
|
|
67
|
+
|
|
68
|
+
bytes_num = bytes_num or IntegerUtils.GetBytesNumber(data_int)
|
|
69
|
+
return data_int.to_bytes(bytes_num, byteorder=endianness, signed=signed)
|
|
70
|
+
|
|
71
|
+
@staticmethod
|
|
72
|
+
def FromBinaryStr(data: Union[bytes, str]) -> int:
|
|
73
|
+
"""
|
|
74
|
+
Convert the specified binary string to integer.
|
|
75
|
+
|
|
76
|
+
Args:
|
|
77
|
+
data (str or bytes): Data
|
|
78
|
+
|
|
79
|
+
Returns:
|
|
80
|
+
int: Integer representation
|
|
81
|
+
"""
|
|
82
|
+
return int(AlgoUtils.Encode(data), 2)
|
|
83
|
+
|
|
84
|
+
@staticmethod
|
|
85
|
+
def ToBinaryStr(data_int: int,
|
|
86
|
+
zero_pad_bit_len: int = 0) -> str:
|
|
87
|
+
"""
|
|
88
|
+
Convert the specified integer to a binary string.
|
|
89
|
+
|
|
90
|
+
Args:
|
|
91
|
+
data_int (int) : Data integer
|
|
92
|
+
zero_pad_bit_len (int, optional): Zero pad length in bits, 0 if not specified
|
|
93
|
+
|
|
94
|
+
Returns:
|
|
95
|
+
str: Binary string
|
|
96
|
+
"""
|
|
97
|
+
return bin(data_int)[2:].zfill(zero_pad_bit_len)
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Copyright (c) 2021 Emanuele Bellocchia
|
|
2
|
+
#
|
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
# furnished to do so, subject to the following conditions:
|
|
9
|
+
#
|
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
|
11
|
+
# all copies or substantial portions of the Software.
|
|
12
|
+
#
|
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
# THE SOFTWARE.
|
|
20
|
+
|
|
21
|
+
"""Module with some string utility functions."""
|
|
22
|
+
|
|
23
|
+
# Imports
|
|
24
|
+
import unicodedata
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class StringUtils:
|
|
28
|
+
"""Class container for string utility functions."""
|
|
29
|
+
|
|
30
|
+
@staticmethod
|
|
31
|
+
def NormalizeNfc(data_str: str) -> str:
|
|
32
|
+
"""
|
|
33
|
+
Normalize string using NFC.
|
|
34
|
+
|
|
35
|
+
Args:
|
|
36
|
+
data_str (str): Input string
|
|
37
|
+
|
|
38
|
+
Returns:
|
|
39
|
+
str: Normalized string
|
|
40
|
+
"""
|
|
41
|
+
return unicodedata.normalize("NFC", data_str)
|
|
42
|
+
|
|
43
|
+
@staticmethod
|
|
44
|
+
def NormalizeNfkd(data_str: str) -> str:
|
|
45
|
+
"""
|
|
46
|
+
Normalize string using NFKD.
|
|
47
|
+
|
|
48
|
+
Args:
|
|
49
|
+
data_str (str): Input string
|
|
50
|
+
|
|
51
|
+
Returns:
|
|
52
|
+
str: Normalized string
|
|
53
|
+
"""
|
|
54
|
+
return unicodedata.normalize("NFKD", data_str)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .literal import Literal
|
|
@@ -0,0 +1,27 @@
|
|
|
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 with Literal type definition."""
|
|
22
|
+
|
|
23
|
+
try:
|
|
24
|
+
from typing import Literal # pylint: disable=unused-import
|
|
25
|
+
except ImportError:
|
|
26
|
+
# Literal not supported by Python 3.7
|
|
27
|
+
from typing_extensions import Literal # type: ignore # noqa: F401
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .wif import WifDecoder, WifEncoder, WifPubKeyModes
|