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,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
|
+
"""
|
|
22
|
+
Module for BIP32 SLIP-0010 keys derivation.
|
|
23
|
+
|
|
24
|
+
References:
|
|
25
|
+
https://github.com/satoshilabs/slips/blob/master/slip-0010.md
|
|
26
|
+
https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
# Imports
|
|
30
|
+
from typing import Tuple, Union
|
|
31
|
+
|
|
32
|
+
from ..base import IBip32KeyDerivator
|
|
33
|
+
from ..bip32_ex import Bip32KeyError
|
|
34
|
+
from ..bip32_key_data import Bip32KeyIndex
|
|
35
|
+
from ..bip32_keys import Bip32PrivateKey, Bip32PublicKey
|
|
36
|
+
from ...ecc import IPoint
|
|
37
|
+
from ...utils.crypto import HmacSha512
|
|
38
|
+
from ...utils.misc import BytesUtils, IntegerUtils
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class Bip32Slip10DerivatorConst:
|
|
42
|
+
"""Class container for BIP32 SLIP-0010 derivator constants."""
|
|
43
|
+
|
|
44
|
+
# Private key prefix
|
|
45
|
+
PRIV_KEY_PREFIX: bytes = b"\x00"
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class Bip32Slip10EcdsaDerivator(IBip32KeyDerivator):
|
|
49
|
+
"""
|
|
50
|
+
BIP32 SLIP-0010 ECDSA key derivator class.
|
|
51
|
+
It allows keys derivation for ECDSA curves in according to BIP32 SLIP-0010.
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
@staticmethod
|
|
55
|
+
def IsPublicDerivationSupported() -> bool:
|
|
56
|
+
"""
|
|
57
|
+
Get if public derivation is supported.
|
|
58
|
+
|
|
59
|
+
Returns:
|
|
60
|
+
bool: True if supported, false otherwise.
|
|
61
|
+
"""
|
|
62
|
+
return True
|
|
63
|
+
|
|
64
|
+
@classmethod
|
|
65
|
+
def CkdPriv(cls,
|
|
66
|
+
priv_key: Bip32PrivateKey,
|
|
67
|
+
pub_key: Bip32PublicKey,
|
|
68
|
+
index: Bip32KeyIndex) -> Tuple[bytes, bytes]:
|
|
69
|
+
"""
|
|
70
|
+
Derive a child key with the specified index using private derivation.
|
|
71
|
+
|
|
72
|
+
Args:
|
|
73
|
+
priv_key (Bip32PrivateKey object): Bip32PrivateKey object
|
|
74
|
+
pub_key (Bip32PublicKey object) : Bip32PublicKey object
|
|
75
|
+
index (Bip32KeyIndex object) : Key index
|
|
76
|
+
|
|
77
|
+
Returns:
|
|
78
|
+
tuple[bytes, bytes]: Private key bytes (index 0) and chain code bytes (index 1)
|
|
79
|
+
|
|
80
|
+
Raises:
|
|
81
|
+
Bip32KeyError: If the index results in an invalid key
|
|
82
|
+
"""
|
|
83
|
+
curve = pub_key.Curve()
|
|
84
|
+
priv_key_bytes = priv_key.Raw().ToBytes()
|
|
85
|
+
|
|
86
|
+
# Data for HMAC
|
|
87
|
+
if index.IsHardened():
|
|
88
|
+
data_bytes = (Bip32Slip10DerivatorConst.PRIV_KEY_PREFIX
|
|
89
|
+
+ priv_key_bytes
|
|
90
|
+
+ index.ToBytes())
|
|
91
|
+
else:
|
|
92
|
+
data_bytes = pub_key.RawCompressed().ToBytes() + index.ToBytes()
|
|
93
|
+
|
|
94
|
+
# Compute HMAC halves
|
|
95
|
+
il_bytes, ir_bytes = HmacSha512.QuickDigestHalves(priv_key.ChainCode().ToBytes(),
|
|
96
|
+
data_bytes)
|
|
97
|
+
|
|
98
|
+
# Construct new key secret from iL and current private key
|
|
99
|
+
il_int = BytesUtils.ToInteger(il_bytes)
|
|
100
|
+
priv_key_int = BytesUtils.ToInteger(priv_key_bytes)
|
|
101
|
+
new_priv_key_bytes = IntegerUtils.ToBytes((il_int + priv_key_int) % curve.Order(),
|
|
102
|
+
bytes_num=curve.PrivateKeyClass().Length())
|
|
103
|
+
|
|
104
|
+
return new_priv_key_bytes, ir_bytes
|
|
105
|
+
|
|
106
|
+
@classmethod
|
|
107
|
+
def CkdPub(cls,
|
|
108
|
+
pub_key: Bip32PublicKey,
|
|
109
|
+
index: Bip32KeyIndex) -> Tuple[Union[bytes, IPoint], bytes]:
|
|
110
|
+
"""
|
|
111
|
+
Derive a child key with the specified index using public derivation.
|
|
112
|
+
|
|
113
|
+
Args:
|
|
114
|
+
pub_key (Bip32PublicKey object): Bip32PublicKey object
|
|
115
|
+
index (Bip32KeyIndex object) : Key index
|
|
116
|
+
|
|
117
|
+
Returns:
|
|
118
|
+
tuple[bytes or IPoint, bytes]: Public key bytes or point (index 0) and chain code bytes (index 1)
|
|
119
|
+
|
|
120
|
+
Raises:
|
|
121
|
+
Bip32KeyError: If the index results in an invalid key
|
|
122
|
+
"""
|
|
123
|
+
# Data for HMAC, same of CkdPriv() for public child key
|
|
124
|
+
data_bytes = pub_key.RawCompressed().ToBytes() + index.ToBytes()
|
|
125
|
+
|
|
126
|
+
# Get HMAC of data
|
|
127
|
+
il_bytes, ir_bytes = HmacSha512.QuickDigestHalves(pub_key.ChainCode().ToBytes(),
|
|
128
|
+
data_bytes)
|
|
129
|
+
il_int = BytesUtils.ToInteger(il_bytes)
|
|
130
|
+
|
|
131
|
+
# Get a new public key point: pub_key_point + G*iL
|
|
132
|
+
new_pub_key_point = pub_key.Point() + (pub_key.Curve().Generator() * il_int)
|
|
133
|
+
|
|
134
|
+
return new_pub_key_point, ir_bytes
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
class Bip32Slip10Ed25519Derivator(IBip32KeyDerivator):
|
|
138
|
+
"""
|
|
139
|
+
BIP32 SLIP-0010 ed25519 key derivator class.
|
|
140
|
+
It allows keys derivation for ed25519 curves in according to BIP32 SLIP-0010.
|
|
141
|
+
"""
|
|
142
|
+
|
|
143
|
+
@staticmethod
|
|
144
|
+
def IsPublicDerivationSupported() -> bool:
|
|
145
|
+
"""
|
|
146
|
+
Get if public derivation is supported.
|
|
147
|
+
|
|
148
|
+
Returns:
|
|
149
|
+
bool: True if supported, false otherwise.
|
|
150
|
+
"""
|
|
151
|
+
return False
|
|
152
|
+
|
|
153
|
+
@classmethod
|
|
154
|
+
def CkdPriv(cls,
|
|
155
|
+
priv_key: Bip32PrivateKey,
|
|
156
|
+
pub_key: Bip32PublicKey,
|
|
157
|
+
index: Bip32KeyIndex) -> Tuple[bytes, bytes]:
|
|
158
|
+
"""
|
|
159
|
+
Derive a child key with the specified index using private derivation.
|
|
160
|
+
|
|
161
|
+
Args:
|
|
162
|
+
priv_key (Bip32PrivateKey object): Bip32PrivateKey object
|
|
163
|
+
pub_key (Bip32PublicKey object) : Bip32PublicKey object
|
|
164
|
+
index (Bip32KeyIndex object) : Key index
|
|
165
|
+
|
|
166
|
+
Returns:
|
|
167
|
+
tuple[bytes, bytes]: Private key bytes (index 0) and chain code bytes (index 1)
|
|
168
|
+
|
|
169
|
+
Raises:
|
|
170
|
+
Bip32KeyError: If the index results in an invalid key
|
|
171
|
+
"""
|
|
172
|
+
if not index.IsHardened():
|
|
173
|
+
raise Bip32KeyError("Private child derivation with not-hardened index is not supported")
|
|
174
|
+
|
|
175
|
+
# Data for HMAC
|
|
176
|
+
data_bytes = (Bip32Slip10DerivatorConst.PRIV_KEY_PREFIX
|
|
177
|
+
+ priv_key.Raw().ToBytes()
|
|
178
|
+
+ index.ToBytes())
|
|
179
|
+
# Compute HMAC halves
|
|
180
|
+
return HmacSha512.QuickDigestHalves(priv_key.ChainCode().ToBytes(),
|
|
181
|
+
data_bytes)
|
|
182
|
+
|
|
183
|
+
@classmethod
|
|
184
|
+
def CkdPub(cls,
|
|
185
|
+
pub_key: Bip32PublicKey,
|
|
186
|
+
index: Bip32KeyIndex) -> Tuple[Union[bytes, IPoint], bytes]:
|
|
187
|
+
"""
|
|
188
|
+
Derive a child key with the specified index using public derivation.
|
|
189
|
+
|
|
190
|
+
Args:
|
|
191
|
+
pub_key (Bip32PublicKey object): Bip32PublicKey object
|
|
192
|
+
index (Bip32KeyIndex object) : Key index
|
|
193
|
+
|
|
194
|
+
Returns:
|
|
195
|
+
tuple[bytes or IPoint, bytes]: Public key bytes or point (index 0) and chain code bytes (index 1)
|
|
196
|
+
|
|
197
|
+
Raises:
|
|
198
|
+
Bip32KeyError: If the index results in an invalid key
|
|
199
|
+
"""
|
|
200
|
+
raise Bip32KeyError("Public child derivation is not supported")
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# Copyright (c) 2021 Emanuele Bellocchia
|
|
2
|
+
#
|
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
# furnished to do so, subject to the following conditions:
|
|
9
|
+
#
|
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
|
11
|
+
# all copies or substantial portions of the Software.
|
|
12
|
+
#
|
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
# THE SOFTWARE.
|
|
20
|
+
|
|
21
|
+
"""
|
|
22
|
+
Module for BIP32 SLIP-0010 master key generation.
|
|
23
|
+
Reference: https://github.com/satoshilabs/slips/blob/master/slip-0010.md
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
# Imports
|
|
27
|
+
from typing import Tuple
|
|
28
|
+
|
|
29
|
+
from ..base import IBip32MstKeyGenerator
|
|
30
|
+
from ...ecc import EllipticCurveGetter, EllipticCurveTypes
|
|
31
|
+
from ...utils.crypto import HmacSha512
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class Bip32Slip10MstKeyGeneratorConst:
|
|
35
|
+
"""Class container for BIP32 SLIP-0010 master key generator constants."""
|
|
36
|
+
|
|
37
|
+
# Minimum length in bytes for seed
|
|
38
|
+
SEED_MIN_BYTE_LEN: int = 16
|
|
39
|
+
# HMAC keys for different curves
|
|
40
|
+
HMAC_KEY_ED25519_BYTES: bytes = b"ed25519 seed"
|
|
41
|
+
HMAC_KEY_NIST256P1_BYTES: bytes = b"Nist256p1 seed"
|
|
42
|
+
HMAC_KEY_SECP256K1_BYTES: bytes = b"Bitcoin seed"
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class _Bip32Slip10MstKeyGenerator:
|
|
46
|
+
"""
|
|
47
|
+
BIP32 SLIP-0010 generic master key generator class.
|
|
48
|
+
It allows master keys generation in according to BIP32 SLIP-0010.
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
@staticmethod
|
|
52
|
+
def GenerateFromSeed(seed_bytes: bytes,
|
|
53
|
+
hmac_key_bytes: bytes,
|
|
54
|
+
curve_type: EllipticCurveTypes) -> Tuple[bytes, bytes]:
|
|
55
|
+
"""
|
|
56
|
+
Generate a master key from the specified seed and return a Bip32Base object.
|
|
57
|
+
|
|
58
|
+
Args:
|
|
59
|
+
seed_bytes (bytes) : Seed bytes
|
|
60
|
+
hmac_key_bytes (bytes) : HMAC key bytes
|
|
61
|
+
|
|
62
|
+
Returns:
|
|
63
|
+
Bip32Base object: Bip32Base object
|
|
64
|
+
|
|
65
|
+
Raises:
|
|
66
|
+
Bip32KeyError: If the seed is not suitable for master key generation
|
|
67
|
+
ValueError: If seed length is not valid
|
|
68
|
+
"""
|
|
69
|
+
if len(seed_bytes) < Bip32Slip10MstKeyGeneratorConst.SEED_MIN_BYTE_LEN:
|
|
70
|
+
raise ValueError(f"Invalid seed length ({len(seed_bytes)})")
|
|
71
|
+
|
|
72
|
+
hmac_half_len = HmacSha512.DigestSize() // 2
|
|
73
|
+
priv_key_cls = EllipticCurveGetter.FromType(curve_type).PrivateKeyClass()
|
|
74
|
+
|
|
75
|
+
# Compute HMAC, retry if the resulting private key is not valid
|
|
76
|
+
hmac = b""
|
|
77
|
+
hmac_data = seed_bytes
|
|
78
|
+
success = False
|
|
79
|
+
|
|
80
|
+
while not success:
|
|
81
|
+
hmac = HmacSha512.QuickDigest(hmac_key_bytes, hmac_data)
|
|
82
|
+
# If private key is not valid, the new HMAC data is the current HMAC
|
|
83
|
+
success = priv_key_cls.IsValidBytes(hmac[:hmac_half_len])
|
|
84
|
+
if not success:
|
|
85
|
+
hmac_data = hmac
|
|
86
|
+
|
|
87
|
+
return hmac[:hmac_half_len], hmac[hmac_half_len:]
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class Bip32Slip10Ed2519MstKeyGenerator(IBip32MstKeyGenerator):
|
|
91
|
+
"""
|
|
92
|
+
BIP32 SLIP-0010 ed25519 master key generator class.
|
|
93
|
+
It allows master keys generation in according to BIP32 SLIP-0010 for ed25519 curve.
|
|
94
|
+
"""
|
|
95
|
+
|
|
96
|
+
@classmethod
|
|
97
|
+
def GenerateFromSeed(cls,
|
|
98
|
+
seed_bytes: bytes) -> Tuple[bytes, bytes]:
|
|
99
|
+
"""
|
|
100
|
+
Generate a master key from the specified seed.
|
|
101
|
+
|
|
102
|
+
Args:
|
|
103
|
+
seed_bytes (bytes): Seed bytes
|
|
104
|
+
|
|
105
|
+
Returns:
|
|
106
|
+
tuple[bytes, bytes]: Private key bytes (index 0) and chain code bytes (index 1)
|
|
107
|
+
|
|
108
|
+
Raises:
|
|
109
|
+
Bip32KeyError: If the seed is not suitable for master key generation
|
|
110
|
+
ValueError: If seed length is not valid
|
|
111
|
+
"""
|
|
112
|
+
return _Bip32Slip10MstKeyGenerator.GenerateFromSeed(seed_bytes,
|
|
113
|
+
Bip32Slip10MstKeyGeneratorConst.HMAC_KEY_ED25519_BYTES,
|
|
114
|
+
EllipticCurveTypes.ED25519)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
class Bip32Slip10Nist256p1MstKeyGenerator(IBip32MstKeyGenerator):
|
|
118
|
+
"""
|
|
119
|
+
BIP32 SLIP-0010 nist256p1 master key generator class.
|
|
120
|
+
It allows master keys generation in according to BIP32 SLIP-0010 for nist256p1 curve.
|
|
121
|
+
"""
|
|
122
|
+
|
|
123
|
+
@classmethod
|
|
124
|
+
def GenerateFromSeed(cls,
|
|
125
|
+
seed_bytes: bytes) -> Tuple[bytes, bytes]:
|
|
126
|
+
"""
|
|
127
|
+
Generate a master key from the specified seed.
|
|
128
|
+
|
|
129
|
+
Args:
|
|
130
|
+
seed_bytes (bytes): Seed bytes
|
|
131
|
+
|
|
132
|
+
Returns:
|
|
133
|
+
tuple[bytes, bytes]: Private key bytes (index 0) and chain code bytes (index 1)
|
|
134
|
+
|
|
135
|
+
Raises:
|
|
136
|
+
Bip32KeyError: If the seed is not suitable for master key generation
|
|
137
|
+
ValueError: If seed length is not valid
|
|
138
|
+
"""
|
|
139
|
+
return _Bip32Slip10MstKeyGenerator.GenerateFromSeed(seed_bytes,
|
|
140
|
+
Bip32Slip10MstKeyGeneratorConst.HMAC_KEY_NIST256P1_BYTES,
|
|
141
|
+
EllipticCurveTypes.NIST256P1)
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
class Bip32Slip10Secp256k1MstKeyGenerator(IBip32MstKeyGenerator):
|
|
145
|
+
"""
|
|
146
|
+
BIP32 SLIP-0010 secp256k1 master key generator class.
|
|
147
|
+
It allows master keys generation in according to BIP32 SLIP-0010 for secp256k1 curve.
|
|
148
|
+
"""
|
|
149
|
+
|
|
150
|
+
@classmethod
|
|
151
|
+
def GenerateFromSeed(cls,
|
|
152
|
+
seed_bytes: bytes) -> Tuple[bytes, bytes]:
|
|
153
|
+
"""
|
|
154
|
+
Generate a master key from the specified seed.
|
|
155
|
+
|
|
156
|
+
Args:
|
|
157
|
+
seed_bytes (bytes): Seed bytes
|
|
158
|
+
|
|
159
|
+
Returns:
|
|
160
|
+
tuple[bytes, bytes]: Private key bytes (index 0) and chain code bytes (index 1)
|
|
161
|
+
|
|
162
|
+
Raises:
|
|
163
|
+
Bip32KeyError: If the seed is not suitable for master key generation
|
|
164
|
+
ValueError: If seed length is not valid
|
|
165
|
+
"""
|
|
166
|
+
return _Bip32Slip10MstKeyGenerator.GenerateFromSeed(seed_bytes,
|
|
167
|
+
Bip32Slip10MstKeyGeneratorConst.HMAC_KEY_SECP256K1_BYTES,
|
|
168
|
+
EllipticCurveTypes.SECP256K1)
|
|
@@ -0,0 +1,82 @@
|
|
|
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 derivation scheme based on secp256k1 curve as defined by BIP32 SLIP-0010."""
|
|
22
|
+
|
|
23
|
+
# Imports
|
|
24
|
+
from typing import Type
|
|
25
|
+
|
|
26
|
+
from ..base import Bip32Base, IBip32KeyDerivator, IBip32MstKeyGenerator
|
|
27
|
+
from ..bip32_const import Bip32Const
|
|
28
|
+
from ..bip32_key_net_ver import Bip32KeyNetVersions
|
|
29
|
+
from .bip32_slip10_key_derivator import Bip32Slip10EcdsaDerivator
|
|
30
|
+
from .bip32_slip10_mst_key_generator import Bip32Slip10Secp256k1MstKeyGenerator
|
|
31
|
+
from ...ecc import EllipticCurveTypes
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class Bip32Slip10Secp256k1(Bip32Base):
|
|
35
|
+
"""
|
|
36
|
+
BIP32 SLIP-0010 secp256k1 v.
|
|
37
|
+
It allows master keys generation and keys derivation using secp256k1 curve.
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
@staticmethod
|
|
41
|
+
def CurveType() -> EllipticCurveTypes:
|
|
42
|
+
"""
|
|
43
|
+
Return the elliptic curve type.
|
|
44
|
+
|
|
45
|
+
Returns:
|
|
46
|
+
EllipticCurveTypes: Curve type
|
|
47
|
+
"""
|
|
48
|
+
return EllipticCurveTypes.SECP256K1
|
|
49
|
+
|
|
50
|
+
@staticmethod
|
|
51
|
+
def _DefaultKeyNetVersion() -> Bip32KeyNetVersions:
|
|
52
|
+
"""
|
|
53
|
+
Return the default key net version.
|
|
54
|
+
|
|
55
|
+
Returns:
|
|
56
|
+
Bip32KeyNetVersions object: Bip32KeyNetVersions object
|
|
57
|
+
"""
|
|
58
|
+
return Bip32Const.MAIN_NET_KEY_NET_VERSIONS
|
|
59
|
+
|
|
60
|
+
@staticmethod
|
|
61
|
+
def _KeyDerivator() -> Type[IBip32KeyDerivator]:
|
|
62
|
+
"""
|
|
63
|
+
Return the key derivator class.
|
|
64
|
+
|
|
65
|
+
Returns:
|
|
66
|
+
IBip32KeyDerivator class: Key derivator class
|
|
67
|
+
"""
|
|
68
|
+
return Bip32Slip10EcdsaDerivator
|
|
69
|
+
|
|
70
|
+
@staticmethod
|
|
71
|
+
def _MasterKeyGenerator() -> Type[IBip32MstKeyGenerator]:
|
|
72
|
+
"""
|
|
73
|
+
Return the master key generator class.
|
|
74
|
+
|
|
75
|
+
Returns:
|
|
76
|
+
IBip32MstKeyGenerator class: Master key generator class
|
|
77
|
+
"""
|
|
78
|
+
return Bip32Slip10Secp256k1MstKeyGenerator
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
# Deprecated: only for compatibility
|
|
82
|
+
Bip32Secp256k1 = Bip32Slip10Secp256k1
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .bip44 import Bip44
|