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,581 @@
|
|
|
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 BIP32 base class."""
|
|
22
|
+
|
|
23
|
+
# Imports
|
|
24
|
+
from __future__ import annotations
|
|
25
|
+
|
|
26
|
+
from abc import ABC, abstractmethod
|
|
27
|
+
from typing import Optional, Type, Union
|
|
28
|
+
|
|
29
|
+
from .ibip32_key_derivator import IBip32KeyDerivator
|
|
30
|
+
from .ibip32_mst_key_generator import IBip32MstKeyGenerator
|
|
31
|
+
from ..bip32_ex import Bip32KeyError
|
|
32
|
+
from ..bip32_key_data import Bip32ChainCode, Bip32Depth, Bip32FingerPrint, Bip32KeyData, Bip32KeyIndex
|
|
33
|
+
from ..bip32_key_net_ver import Bip32KeyNetVersions
|
|
34
|
+
from ..bip32_key_ser import Bip32KeyDeserializer
|
|
35
|
+
from ..bip32_keys import Bip32PrivateKey, Bip32PublicKey
|
|
36
|
+
from ..bip32_path import Bip32Path, Bip32PathParser
|
|
37
|
+
from ...ecc import EllipticCurve, EllipticCurveGetter, EllipticCurveTypes, IPoint, IPrivateKey, IPublicKey
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class Bip32Base(ABC):
|
|
41
|
+
"""
|
|
42
|
+
BIP32 base class.
|
|
43
|
+
It allows master key generation and children keys derivation in according to BIP-0032/SLIP-0010.
|
|
44
|
+
It shall be derived to implement derivation for a specific elliptic curve.
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
m_priv_key: Optional[Bip32PrivateKey]
|
|
48
|
+
m_pub_key: Bip32PublicKey
|
|
49
|
+
|
|
50
|
+
#
|
|
51
|
+
# Class methods for construction
|
|
52
|
+
#
|
|
53
|
+
|
|
54
|
+
@classmethod
|
|
55
|
+
def FromSeed(cls,
|
|
56
|
+
seed_bytes: bytes,
|
|
57
|
+
key_net_ver: Optional[Bip32KeyNetVersions] = None) -> Bip32Base:
|
|
58
|
+
"""
|
|
59
|
+
Create a Bip32 object from the specified seed (e.g. BIP39 seed).
|
|
60
|
+
|
|
61
|
+
Args:
|
|
62
|
+
seed_bytes (bytes) : Seed bytes
|
|
63
|
+
key_net_ver (Bip32KeyNetVersions object, optional): Bip32KeyNetVersions object
|
|
64
|
+
(default: specific class key net version)
|
|
65
|
+
|
|
66
|
+
Returns:
|
|
67
|
+
Bip32Base object: Bip32Base object
|
|
68
|
+
|
|
69
|
+
Raises:
|
|
70
|
+
ValueError: If the seed is too short
|
|
71
|
+
Bip32KeyError: If the seed is not suitable for master key generation
|
|
72
|
+
"""
|
|
73
|
+
priv_key_bytes, chain_code_bytes = cls._MasterKeyGenerator().GenerateFromSeed(seed_bytes)
|
|
74
|
+
|
|
75
|
+
return cls(
|
|
76
|
+
priv_key=priv_key_bytes,
|
|
77
|
+
pub_key=None,
|
|
78
|
+
key_data=Bip32KeyData(chain_code=chain_code_bytes),
|
|
79
|
+
key_net_ver=key_net_ver or cls._DefaultKeyNetVersion()
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
@classmethod
|
|
83
|
+
def FromSeedAndPath(cls,
|
|
84
|
+
seed_bytes: bytes,
|
|
85
|
+
path: Union[str, Bip32Path],
|
|
86
|
+
key_net_ver: Optional[Bip32KeyNetVersions] = None) -> Bip32Base:
|
|
87
|
+
"""
|
|
88
|
+
Create a Bip32 object from the specified seed (e.g. BIP39 seed) and path.
|
|
89
|
+
|
|
90
|
+
Args:
|
|
91
|
+
seed_bytes (bytes) : Seed bytes
|
|
92
|
+
path (str or Bip32Path object) : Path
|
|
93
|
+
key_net_ver (Bip32KeyNetVersions object, optional): Bip32KeyNetVersions object
|
|
94
|
+
(default: specific class key net version)
|
|
95
|
+
|
|
96
|
+
Returns:
|
|
97
|
+
Bip32Base object: Bip32Base object
|
|
98
|
+
|
|
99
|
+
Raises:
|
|
100
|
+
ValueError: If the seed length is too short
|
|
101
|
+
Bip32PathError: If the path is not valid
|
|
102
|
+
Bip32KeyError: If the seed is not suitable for master key generation
|
|
103
|
+
"""
|
|
104
|
+
key_net_ver = key_net_ver or cls._DefaultKeyNetVersion()
|
|
105
|
+
return cls.FromSeed(seed_bytes, key_net_ver).DerivePath(path)
|
|
106
|
+
|
|
107
|
+
@classmethod
|
|
108
|
+
def FromExtendedKey(cls,
|
|
109
|
+
ex_key_str: str,
|
|
110
|
+
key_net_ver: Optional[Bip32KeyNetVersions] = None) -> Bip32Base:
|
|
111
|
+
"""
|
|
112
|
+
Create a Bip32 object from the specified extended key.
|
|
113
|
+
|
|
114
|
+
Args:
|
|
115
|
+
ex_key_str (str) : Extended key string
|
|
116
|
+
key_net_ver (Bip32KeyNetVersions object, optional): Bip32KeyNetVersions object
|
|
117
|
+
(default: specific class key net version)
|
|
118
|
+
|
|
119
|
+
Returns:
|
|
120
|
+
Bip32Base object: Bip32Base object
|
|
121
|
+
|
|
122
|
+
Raises:
|
|
123
|
+
Bip32KeyError: If the key is not valid
|
|
124
|
+
"""
|
|
125
|
+
key_net_ver = key_net_ver or cls._DefaultKeyNetVersion()
|
|
126
|
+
|
|
127
|
+
# De-serialize key
|
|
128
|
+
deser_key = Bip32KeyDeserializer.DeserializeKey(ex_key_str, key_net_ver)
|
|
129
|
+
# Get key parts
|
|
130
|
+
key_bytes, key_data, is_public = deser_key.KeyBytes(), deser_key.KeyData(), deser_key.IsPublic()
|
|
131
|
+
|
|
132
|
+
# If depth is zero, fingerprint shall be the master one and child index shall be zero
|
|
133
|
+
if key_data.Depth() == 0:
|
|
134
|
+
if not key_data.ParentFingerPrint().IsMasterKey():
|
|
135
|
+
raise Bip32KeyError(
|
|
136
|
+
f"Invalid extended master key (wrong fingerprint: {key_data.ParentFingerPrint().ToHex()})"
|
|
137
|
+
)
|
|
138
|
+
if key_data.Index() != 0:
|
|
139
|
+
raise Bip32KeyError(f"Invalid extended master key (wrong child index: {key_data.Index().ToInt()})")
|
|
140
|
+
|
|
141
|
+
return cls(
|
|
142
|
+
priv_key=key_bytes if not is_public else None,
|
|
143
|
+
pub_key=key_bytes if is_public else None,
|
|
144
|
+
key_data=key_data,
|
|
145
|
+
key_net_ver=key_net_ver
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
@classmethod
|
|
149
|
+
def FromPrivateKey(cls,
|
|
150
|
+
priv_key: Union[bytes, IPrivateKey],
|
|
151
|
+
key_data: Bip32KeyData = Bip32KeyData(),
|
|
152
|
+
key_net_ver: Optional[Bip32KeyNetVersions] = None) -> Bip32Base:
|
|
153
|
+
"""
|
|
154
|
+
Create a Bip32 object from the specified private key and derivation data.
|
|
155
|
+
If only the private key bytes are specified, the key will be considered a master key with
|
|
156
|
+
the chain code set to zero, since there is no way to recover the key derivation data.
|
|
157
|
+
|
|
158
|
+
Args:
|
|
159
|
+
priv_key (bytes or IPrivateKey) : Private key
|
|
160
|
+
key_data (Bip32KeyData object, optional) : Key data (default: all zeros)
|
|
161
|
+
key_net_ver (Bip32KeyNetVersions object, optional): Bip32KeyNetVersions object
|
|
162
|
+
(default: specific class key net version)
|
|
163
|
+
|
|
164
|
+
Returns:
|
|
165
|
+
Bip32Base object: Bip32Base object
|
|
166
|
+
|
|
167
|
+
Raises:
|
|
168
|
+
Bip32KeyError: If the key is not valid
|
|
169
|
+
"""
|
|
170
|
+
return cls(
|
|
171
|
+
priv_key=priv_key,
|
|
172
|
+
pub_key=None,
|
|
173
|
+
key_data=key_data,
|
|
174
|
+
key_net_ver=key_net_ver or cls._DefaultKeyNetVersion()
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
@classmethod
|
|
178
|
+
def FromPublicKey(cls,
|
|
179
|
+
pub_key: Union[bytes, IPoint, IPublicKey],
|
|
180
|
+
key_data: Bip32KeyData = Bip32KeyData(),
|
|
181
|
+
key_net_ver: Optional[Bip32KeyNetVersions] = None) -> Bip32Base:
|
|
182
|
+
"""
|
|
183
|
+
Create a Bip32 object from the specified public key and derivation data.
|
|
184
|
+
If only the public key bytes are specified, the key will be considered a master key with
|
|
185
|
+
the chain code set to zero, since there is no way to recover the key derivation data.
|
|
186
|
+
|
|
187
|
+
Args:
|
|
188
|
+
pub_key (bytes, IPoint or IPublicKey) : Public key
|
|
189
|
+
key_data (Bip32KeyData object, optional) : Key data (default: all zeros)
|
|
190
|
+
key_net_ver (Bip32KeyNetVersions object, optional): Bip32KeyNetVersions object
|
|
191
|
+
(default: specific class key net version)
|
|
192
|
+
|
|
193
|
+
Returns:
|
|
194
|
+
Bip32Base object: Bip32Base object
|
|
195
|
+
|
|
196
|
+
Raises:
|
|
197
|
+
Bip32KeyError: If the key is not valid
|
|
198
|
+
"""
|
|
199
|
+
return cls(
|
|
200
|
+
priv_key=None,
|
|
201
|
+
pub_key=pub_key,
|
|
202
|
+
key_data=key_data,
|
|
203
|
+
key_net_ver=key_net_ver or cls._DefaultKeyNetVersion()
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
#
|
|
207
|
+
# Public methods
|
|
208
|
+
#
|
|
209
|
+
|
|
210
|
+
def __init__(self,
|
|
211
|
+
priv_key: Optional[Union[bytes, IPrivateKey]],
|
|
212
|
+
pub_key: Optional[Union[bytes, IPoint, IPublicKey]],
|
|
213
|
+
key_data: Bip32KeyData,
|
|
214
|
+
key_net_ver: Bip32KeyNetVersions) -> None:
|
|
215
|
+
"""
|
|
216
|
+
Construct class.
|
|
217
|
+
|
|
218
|
+
Args:
|
|
219
|
+
priv_key (bytes or IPrivateKey) : Private key (None for a public-only object)
|
|
220
|
+
pub_key (bytes, IPoint or IPublicKey) : Public key (only needed for a public-only object)
|
|
221
|
+
If priv_key is not None, it'll be discarded
|
|
222
|
+
key_data (Bip32KeyData object) : Key data
|
|
223
|
+
key_net_ver (Bip32KeyNetVersions object): Bip32KeyNetVersions object
|
|
224
|
+
|
|
225
|
+
Raises:
|
|
226
|
+
Bip32KeyError: If the constructed key is not valid
|
|
227
|
+
"""
|
|
228
|
+
curve = self.Curve()
|
|
229
|
+
|
|
230
|
+
# Private key object
|
|
231
|
+
if priv_key is not None:
|
|
232
|
+
# Check that key type matches the Bip curve
|
|
233
|
+
if not isinstance(priv_key, bytes) and not isinstance(priv_key, curve.PrivateKeyClass()):
|
|
234
|
+
raise Bip32KeyError(f"Invalid private key class, a {curve.Name()} key is required")
|
|
235
|
+
|
|
236
|
+
self.m_priv_key = Bip32PrivateKey.FromBytesOrKeyObject(priv_key,
|
|
237
|
+
key_data,
|
|
238
|
+
key_net_ver,
|
|
239
|
+
self.CurveType())
|
|
240
|
+
self.m_pub_key = self.m_priv_key.PublicKey()
|
|
241
|
+
# Public-only object
|
|
242
|
+
else:
|
|
243
|
+
# Check that key type matches the Bip curve
|
|
244
|
+
if (not isinstance(pub_key, bytes)
|
|
245
|
+
and not isinstance(pub_key, curve.PointClass())
|
|
246
|
+
and not isinstance(pub_key, curve.PublicKeyClass())):
|
|
247
|
+
raise Bip32KeyError(f"Invalid public key class, a {curve.Name()} key or point is required")
|
|
248
|
+
|
|
249
|
+
self.m_priv_key = None
|
|
250
|
+
self.m_pub_key = Bip32PublicKey.FromBytesOrKeyObject(pub_key,
|
|
251
|
+
key_data,
|
|
252
|
+
key_net_ver,
|
|
253
|
+
self.CurveType())
|
|
254
|
+
|
|
255
|
+
def ChildKey(self,
|
|
256
|
+
index: Union[int, Bip32KeyIndex]) -> Bip32Base:
|
|
257
|
+
"""
|
|
258
|
+
Create and return a child key of the current one with the specified index.
|
|
259
|
+
The index shall be hardened using HardenIndex method to use the private derivation algorithm.
|
|
260
|
+
|
|
261
|
+
Args:
|
|
262
|
+
index (int or Bip32KeyIndex object): Index
|
|
263
|
+
|
|
264
|
+
Returns:
|
|
265
|
+
Bip32Base object: Bip32Base object
|
|
266
|
+
|
|
267
|
+
Raises:
|
|
268
|
+
Bip32KeyError: If the index results in an invalid key
|
|
269
|
+
"""
|
|
270
|
+
index = self.__GetIndex(index)
|
|
271
|
+
return self.__ValidateAndCkdPriv(index) if not self.IsPublicOnly() else self.__ValidateAndCkdPub(index)
|
|
272
|
+
|
|
273
|
+
def DerivePath(self,
|
|
274
|
+
path: Union[str, Bip32Path]) -> Bip32Base:
|
|
275
|
+
"""
|
|
276
|
+
Derive children keys from the specified path.
|
|
277
|
+
|
|
278
|
+
Args:
|
|
279
|
+
path (str or Bip32Path object): Path
|
|
280
|
+
|
|
281
|
+
Returns:
|
|
282
|
+
Bip32Base object: Bip32Base object
|
|
283
|
+
|
|
284
|
+
Raises:
|
|
285
|
+
Bip32KeyError: If the index results in an invalid key
|
|
286
|
+
Bip32PathError: If the path is not valid
|
|
287
|
+
ValueError: If the path is a master path and the key is a child key
|
|
288
|
+
"""
|
|
289
|
+
path = self.__GetPath(path)
|
|
290
|
+
if self.Depth() > 0 and path.IsAbsolute():
|
|
291
|
+
raise ValueError("Absolute paths can only be derived from a master key, not child ones")
|
|
292
|
+
|
|
293
|
+
bip32_obj = self
|
|
294
|
+
# Derive children keys
|
|
295
|
+
for path_elem in path:
|
|
296
|
+
bip32_obj = bip32_obj.ChildKey(path_elem)
|
|
297
|
+
|
|
298
|
+
return bip32_obj
|
|
299
|
+
|
|
300
|
+
def ConvertToPublic(self) -> None:
|
|
301
|
+
"""Convert the object into a public one."""
|
|
302
|
+
self.m_priv_key = None
|
|
303
|
+
|
|
304
|
+
def IsPublicOnly(self) -> bool:
|
|
305
|
+
"""
|
|
306
|
+
Get if it's public-only.
|
|
307
|
+
|
|
308
|
+
Returns:
|
|
309
|
+
bool: True if public-only, false otherwise
|
|
310
|
+
"""
|
|
311
|
+
return self.m_priv_key is None
|
|
312
|
+
|
|
313
|
+
def PrivateKey(self) -> Bip32PrivateKey:
|
|
314
|
+
"""
|
|
315
|
+
Return private key object.
|
|
316
|
+
|
|
317
|
+
Returns:
|
|
318
|
+
Bip32PrivateKey object: Bip32PrivateKey object
|
|
319
|
+
|
|
320
|
+
Raises:
|
|
321
|
+
Bip32KeyError: If internal key is public-only
|
|
322
|
+
"""
|
|
323
|
+
if self.IsPublicOnly():
|
|
324
|
+
raise Bip32KeyError("Public-only deterministic keys have no private half")
|
|
325
|
+
|
|
326
|
+
assert isinstance(self.m_priv_key, Bip32PrivateKey)
|
|
327
|
+
return self.m_priv_key
|
|
328
|
+
|
|
329
|
+
def PublicKey(self) -> Bip32PublicKey:
|
|
330
|
+
"""
|
|
331
|
+
Return public key object.
|
|
332
|
+
|
|
333
|
+
Returns:
|
|
334
|
+
Bip32PublicKey object: Bip32PublicKey object
|
|
335
|
+
"""
|
|
336
|
+
return self.m_pub_key
|
|
337
|
+
|
|
338
|
+
def KeyNetVersions(self) -> Bip32KeyNetVersions:
|
|
339
|
+
"""
|
|
340
|
+
Get key net versions.
|
|
341
|
+
|
|
342
|
+
Returns:
|
|
343
|
+
Bip32KeyNetVersions object: Bip32KeyNetVersions object
|
|
344
|
+
"""
|
|
345
|
+
return self.m_pub_key.KeyNetVersions()
|
|
346
|
+
|
|
347
|
+
def Depth(self) -> Bip32Depth:
|
|
348
|
+
"""
|
|
349
|
+
Get current depth.
|
|
350
|
+
|
|
351
|
+
Returns:
|
|
352
|
+
Bip32Depth object: Current depth
|
|
353
|
+
"""
|
|
354
|
+
return self.m_pub_key.Data().Depth()
|
|
355
|
+
|
|
356
|
+
def Index(self) -> Bip32KeyIndex:
|
|
357
|
+
"""
|
|
358
|
+
Get current index.
|
|
359
|
+
|
|
360
|
+
Returns:
|
|
361
|
+
Bip32KeyIndex object: Current index
|
|
362
|
+
"""
|
|
363
|
+
return self.m_pub_key.Data().Index()
|
|
364
|
+
|
|
365
|
+
def ChainCode(self) -> Bip32ChainCode:
|
|
366
|
+
"""
|
|
367
|
+
Get chain code.
|
|
368
|
+
|
|
369
|
+
Returns:
|
|
370
|
+
Bip32ChainCode: Chain code
|
|
371
|
+
"""
|
|
372
|
+
return self.m_pub_key.ChainCode()
|
|
373
|
+
|
|
374
|
+
def FingerPrint(self) -> Bip32FingerPrint:
|
|
375
|
+
"""
|
|
376
|
+
Get public key fingerprint.
|
|
377
|
+
|
|
378
|
+
Returns:
|
|
379
|
+
Bip32FingerPrint object: Public key fingerprint bytes
|
|
380
|
+
"""
|
|
381
|
+
return self.m_pub_key.FingerPrint()
|
|
382
|
+
|
|
383
|
+
def ParentFingerPrint(self) -> Bip32FingerPrint:
|
|
384
|
+
"""
|
|
385
|
+
Get parent fingerprint.
|
|
386
|
+
|
|
387
|
+
Returns:
|
|
388
|
+
Bip32FingerPrint object: Parent fingerprint bytes
|
|
389
|
+
"""
|
|
390
|
+
return self.m_pub_key.Data().ParentFingerPrint()
|
|
391
|
+
|
|
392
|
+
@classmethod
|
|
393
|
+
def Curve(cls) -> EllipticCurve:
|
|
394
|
+
"""
|
|
395
|
+
Return the elliptic curve.
|
|
396
|
+
|
|
397
|
+
Returns:
|
|
398
|
+
EllipticCurve object: EllipticCurve object
|
|
399
|
+
"""
|
|
400
|
+
return EllipticCurveGetter.FromType(cls.CurveType())
|
|
401
|
+
|
|
402
|
+
@classmethod
|
|
403
|
+
def IsPublicDerivationSupported(cls) -> bool:
|
|
404
|
+
"""
|
|
405
|
+
Get if public derivation is supported.
|
|
406
|
+
|
|
407
|
+
Returns:
|
|
408
|
+
bool: True if supported, false otherwise.
|
|
409
|
+
"""
|
|
410
|
+
return cls._KeyDerivator().IsPublicDerivationSupported()
|
|
411
|
+
|
|
412
|
+
#
|
|
413
|
+
# Private methods
|
|
414
|
+
#
|
|
415
|
+
|
|
416
|
+
def __ValidateAndCkdPriv(self,
|
|
417
|
+
index: Bip32KeyIndex) -> Bip32Base:
|
|
418
|
+
"""
|
|
419
|
+
Check the key index validity and create a child key with the specified index using private derivation.
|
|
420
|
+
|
|
421
|
+
Args:
|
|
422
|
+
index (Bip32KeyIndex object): Key index
|
|
423
|
+
|
|
424
|
+
Returns:
|
|
425
|
+
Bip32Base object: Bip32Base object
|
|
426
|
+
|
|
427
|
+
Raises:
|
|
428
|
+
Bip32KeyError: If the index results in an invalid key
|
|
429
|
+
"""
|
|
430
|
+
return self.__CkdPriv(index)
|
|
431
|
+
|
|
432
|
+
def __ValidateAndCkdPub(self,
|
|
433
|
+
index: Bip32KeyIndex) -> Bip32Base:
|
|
434
|
+
"""
|
|
435
|
+
Check the key index validity and create a child key with the specified index using public derivation.
|
|
436
|
+
|
|
437
|
+
Args:
|
|
438
|
+
index (Bip32KeyIndex object): Key index
|
|
439
|
+
|
|
440
|
+
Returns:
|
|
441
|
+
Bip32Base object: Bip32Base object
|
|
442
|
+
|
|
443
|
+
Raises:
|
|
444
|
+
Bip32KeyError: If the index results in an invalid key
|
|
445
|
+
"""
|
|
446
|
+
|
|
447
|
+
# Hardened index is not supported for public derivation
|
|
448
|
+
if index.IsHardened():
|
|
449
|
+
raise Bip32KeyError("Public child derivation cannot be used to create a hardened child key")
|
|
450
|
+
|
|
451
|
+
return self.__CkdPub(index)
|
|
452
|
+
|
|
453
|
+
def __CkdPriv(self,
|
|
454
|
+
index: Bip32KeyIndex) -> Bip32Base:
|
|
455
|
+
"""
|
|
456
|
+
Derive a child key with the specified index using private derivation.
|
|
457
|
+
|
|
458
|
+
Args:
|
|
459
|
+
index (Bip32KeyIndex object): Key index
|
|
460
|
+
|
|
461
|
+
Returns:
|
|
462
|
+
Bip32Base object: Bip32Base object
|
|
463
|
+
|
|
464
|
+
Raises:
|
|
465
|
+
Bip32KeyError: If the index results in an invalid key
|
|
466
|
+
"""
|
|
467
|
+
assert self.m_priv_key is not None
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
priv_key_bytes, chain_code_bytes = self._KeyDerivator().CkdPriv(self.m_priv_key,
|
|
471
|
+
self.m_pub_key,
|
|
472
|
+
index)
|
|
473
|
+
return self.__class__(
|
|
474
|
+
priv_key=priv_key_bytes,
|
|
475
|
+
pub_key=None,
|
|
476
|
+
key_data=Bip32KeyData(
|
|
477
|
+
chain_code=chain_code_bytes,
|
|
478
|
+
depth=self.Depth().Increase(),
|
|
479
|
+
index=index,
|
|
480
|
+
parent_fprint=self.FingerPrint()
|
|
481
|
+
),
|
|
482
|
+
key_net_ver=self.KeyNetVersions()
|
|
483
|
+
)
|
|
484
|
+
|
|
485
|
+
def __CkdPub(self,
|
|
486
|
+
index: Bip32KeyIndex) -> Bip32Base:
|
|
487
|
+
"""
|
|
488
|
+
Derive a child key with the specified index using public derivation.
|
|
489
|
+
|
|
490
|
+
Args:
|
|
491
|
+
index (Bip32KeyIndex object): Key index
|
|
492
|
+
|
|
493
|
+
Returns:
|
|
494
|
+
Bip32Base object: Bip32Base object
|
|
495
|
+
|
|
496
|
+
Raises:
|
|
497
|
+
Bip32KeyError: If the index results in an invalid key
|
|
498
|
+
"""
|
|
499
|
+
pub_key_bytes, chain_code_bytes = self._KeyDerivator().CkdPub(self.m_pub_key,
|
|
500
|
+
index)
|
|
501
|
+
return self.__class__(
|
|
502
|
+
priv_key=None,
|
|
503
|
+
pub_key=pub_key_bytes,
|
|
504
|
+
key_data=Bip32KeyData(
|
|
505
|
+
chain_code=chain_code_bytes,
|
|
506
|
+
depth=self.Depth().Increase(),
|
|
507
|
+
index=index,
|
|
508
|
+
parent_fprint=self.FingerPrint()
|
|
509
|
+
),
|
|
510
|
+
key_net_ver=self.KeyNetVersions()
|
|
511
|
+
)
|
|
512
|
+
|
|
513
|
+
@staticmethod
|
|
514
|
+
def __GetIndex(index: Union[int, Bip32KeyIndex]) -> Bip32KeyIndex:
|
|
515
|
+
"""
|
|
516
|
+
Get index object.
|
|
517
|
+
|
|
518
|
+
Args:
|
|
519
|
+
index (int or Bip32KeyIndex): Index
|
|
520
|
+
|
|
521
|
+
Returns:
|
|
522
|
+
Bip32KeyIndex object: Bip32KeyIndex object
|
|
523
|
+
"""
|
|
524
|
+
return Bip32KeyIndex(index) if isinstance(index, int) else index
|
|
525
|
+
|
|
526
|
+
@staticmethod
|
|
527
|
+
def __GetPath(path: Union[str, Bip32Path]) -> Bip32Path:
|
|
528
|
+
"""
|
|
529
|
+
Get path object.
|
|
530
|
+
|
|
531
|
+
Args:
|
|
532
|
+
path (str or Bip32Path): Path
|
|
533
|
+
|
|
534
|
+
Returns:
|
|
535
|
+
Bip32Path object: Bip32Path object
|
|
536
|
+
"""
|
|
537
|
+
return Bip32PathParser.Parse(path) if isinstance(path, str) else path
|
|
538
|
+
|
|
539
|
+
#
|
|
540
|
+
# Abstract methods
|
|
541
|
+
#
|
|
542
|
+
|
|
543
|
+
@staticmethod
|
|
544
|
+
@abstractmethod
|
|
545
|
+
def CurveType() -> EllipticCurveTypes:
|
|
546
|
+
"""
|
|
547
|
+
Return the elliptic curve type.
|
|
548
|
+
|
|
549
|
+
Returns:
|
|
550
|
+
EllipticCurveTypes: Curve type
|
|
551
|
+
"""
|
|
552
|
+
|
|
553
|
+
@staticmethod
|
|
554
|
+
@abstractmethod
|
|
555
|
+
def _DefaultKeyNetVersion() -> Bip32KeyNetVersions:
|
|
556
|
+
"""
|
|
557
|
+
Return the default key net version.
|
|
558
|
+
|
|
559
|
+
Returns:
|
|
560
|
+
Bip32KeyNetVersions object: Bip32KeyNetVersions object
|
|
561
|
+
"""
|
|
562
|
+
|
|
563
|
+
@staticmethod
|
|
564
|
+
@abstractmethod
|
|
565
|
+
def _KeyDerivator() -> Type[IBip32KeyDerivator]:
|
|
566
|
+
"""
|
|
567
|
+
Return the key derivator class.
|
|
568
|
+
|
|
569
|
+
Returns:
|
|
570
|
+
IBip32KeyDerivator class: Key derivator class
|
|
571
|
+
"""
|
|
572
|
+
|
|
573
|
+
@staticmethod
|
|
574
|
+
@abstractmethod
|
|
575
|
+
def _MasterKeyGenerator() -> Type[IBip32MstKeyGenerator]:
|
|
576
|
+
"""
|
|
577
|
+
Return the master key generator class.
|
|
578
|
+
|
|
579
|
+
Returns:
|
|
580
|
+
IBip32MstKeyGenerator class: Master key generator class
|
|
581
|
+
"""
|
|
@@ -0,0 +1,83 @@
|
|
|
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 BIP32 SLIP-0010 keys derivation."""
|
|
22
|
+
|
|
23
|
+
# Imports
|
|
24
|
+
from abc import ABC, abstractmethod
|
|
25
|
+
from typing import Tuple, Union
|
|
26
|
+
|
|
27
|
+
from ..bip32_key_data import Bip32KeyIndex
|
|
28
|
+
from ..bip32_keys import Bip32PrivateKey, Bip32PublicKey
|
|
29
|
+
from ...ecc import IPoint
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class IBip32KeyDerivator(ABC):
|
|
33
|
+
"""Interface for generic BIP32 key derivator."""
|
|
34
|
+
|
|
35
|
+
@staticmethod
|
|
36
|
+
@abstractmethod
|
|
37
|
+
def IsPublicDerivationSupported() -> bool:
|
|
38
|
+
"""
|
|
39
|
+
Get if public derivation is supported.
|
|
40
|
+
|
|
41
|
+
Returns:
|
|
42
|
+
bool: True if supported, false otherwise.
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
@classmethod
|
|
46
|
+
@abstractmethod
|
|
47
|
+
def CkdPriv(cls,
|
|
48
|
+
priv_key: Bip32PrivateKey,
|
|
49
|
+
pub_key: Bip32PublicKey,
|
|
50
|
+
index: Bip32KeyIndex) -> Tuple[bytes, bytes]:
|
|
51
|
+
"""
|
|
52
|
+
Derive a child key with the specified index using private derivation.
|
|
53
|
+
|
|
54
|
+
Args:
|
|
55
|
+
priv_key (Bip32PrivateKey object): Bip32PrivateKey object
|
|
56
|
+
pub_key (Bip32PublicKey object) : Bip32PublicKey object
|
|
57
|
+
index (Bip32KeyIndex object) : Key index
|
|
58
|
+
|
|
59
|
+
Returns:
|
|
60
|
+
tuple[bytes, bytes]: Private key bytes (index 0) and chain code bytes (index 1)
|
|
61
|
+
|
|
62
|
+
Raises:
|
|
63
|
+
Bip32KeyError: If the index results in an invalid key
|
|
64
|
+
"""
|
|
65
|
+
|
|
66
|
+
@classmethod
|
|
67
|
+
@abstractmethod
|
|
68
|
+
def CkdPub(cls,
|
|
69
|
+
pub_key: Bip32PublicKey,
|
|
70
|
+
index: Bip32KeyIndex) -> Tuple[Union[bytes, IPoint], bytes]:
|
|
71
|
+
"""
|
|
72
|
+
Derive a child key with the specified index using public derivation.
|
|
73
|
+
|
|
74
|
+
Args:
|
|
75
|
+
pub_key (Bip32PublicKey object): Bip32PublicKey object
|
|
76
|
+
index (Bip32KeyIndex object) : Key index
|
|
77
|
+
|
|
78
|
+
Returns:
|
|
79
|
+
tuple[bytes or IPoint, bytes]: Public key bytes or point (index 0) and chain code bytes (index 1)
|
|
80
|
+
|
|
81
|
+
Raises:
|
|
82
|
+
Bip32KeyError: If the index results in an invalid key
|
|
83
|
+
"""
|