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,72 @@
|
|
|
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 utility functions."""
|
|
22
|
+
|
|
23
|
+
# Imports
|
|
24
|
+
from .bip32_key_data import Bip32KeyIndex
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class Bip32Utils:
|
|
28
|
+
"""
|
|
29
|
+
BIP32 utility class.
|
|
30
|
+
It contains some helper methods for Bip32 indexes.
|
|
31
|
+
|
|
32
|
+
Deprecated: only for compatibility, methods were moved to Bip32KeyIndex.
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
@staticmethod
|
|
36
|
+
def HardenIndex(index: int) -> int:
|
|
37
|
+
"""
|
|
38
|
+
Harden the specified index and return it.
|
|
39
|
+
|
|
40
|
+
Args:
|
|
41
|
+
index (int): Index
|
|
42
|
+
|
|
43
|
+
Returns:
|
|
44
|
+
int: Hardened index
|
|
45
|
+
"""
|
|
46
|
+
return Bip32KeyIndex.HardenIndex(index)
|
|
47
|
+
|
|
48
|
+
@staticmethod
|
|
49
|
+
def UnhardenIndex(index: int) -> int:
|
|
50
|
+
"""
|
|
51
|
+
Unharden the specified index and return it.
|
|
52
|
+
|
|
53
|
+
Args:
|
|
54
|
+
index (int): Index
|
|
55
|
+
|
|
56
|
+
Returns:
|
|
57
|
+
int: Unhardened index
|
|
58
|
+
"""
|
|
59
|
+
return Bip32KeyIndex.UnhardenIndex(index)
|
|
60
|
+
|
|
61
|
+
@staticmethod
|
|
62
|
+
def IsHardenedIndex(index: int) -> bool:
|
|
63
|
+
"""
|
|
64
|
+
Get if the specified index is hardened.
|
|
65
|
+
|
|
66
|
+
Args:
|
|
67
|
+
index (int): Index
|
|
68
|
+
|
|
69
|
+
Returns:
|
|
70
|
+
bool: True if hardened, false otherwise
|
|
71
|
+
"""
|
|
72
|
+
return Bip32KeyIndex.IsHardenedIndex(index)
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
# from .kholaw.bip32_kholaw_ed25519 import Bip32Ed25519Kholaw, Bip32KholawEd25519
|
|
2
|
+
# from .kholaw.bip32_kholaw_ed25519_key_derivator import Bip32KholawEd25519KeyDerivator
|
|
3
|
+
# from .kholaw.bip32_kholaw_key_derivator_base import Bip32KholawEd25519KeyDerivatorBase
|
|
4
|
+
# from .kholaw.bip32_kholaw_mst_key_generator import Bip32KholawEd25519MstKeyGenerator
|
|
@@ -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 keys derivation based on ed25519 curve as defined by BIP32 Khovratovich/Law."""
|
|
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 .kholaw.bip32_kholaw_ed25519_key_derivator import Bip32KholawEd25519KeyDerivator
|
|
30
|
+
from .kholaw.bip32_kholaw_mst_key_generator import Bip32KholawEd25519MstKeyGenerator
|
|
31
|
+
from bip_utils.ecc import EllipticCurveTypes
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class Bip32KholawEd25519(Bip32Base):
|
|
35
|
+
"""
|
|
36
|
+
BIP32 Khovratovich/Law ed25519 class.
|
|
37
|
+
It allows master keys generation and keys derivation using ed25519 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.ED25519_KHOLAW
|
|
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.KHOLAW_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 Bip32KholawEd25519KeyDerivator
|
|
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 Bip32KholawEd25519MstKeyGenerator
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
# Deprecated: only for compatibility
|
|
82
|
+
Bip32Ed25519Kholaw = Bip32KholawEd25519
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# Copyright (c) 2022 Emanuele Bellocchia
|
|
2
|
+
#
|
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
# furnished to do so, subject to the following conditions:
|
|
9
|
+
#
|
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
|
11
|
+
# all copies or substantial portions of the Software.
|
|
12
|
+
#
|
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
# THE SOFTWARE.
|
|
20
|
+
|
|
21
|
+
"""
|
|
22
|
+
Module for BIP32 Khovratovich/Law keys derivation.
|
|
23
|
+
Reference: https://github.com/LedgerHQ/orakolo/blob/master/papers/Ed25519_BIP%20Final.pdf
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
# Imports
|
|
27
|
+
from .bip32_ex import Bip32KeyError
|
|
28
|
+
from .bip32_key_data import Bip32KeyIndex
|
|
29
|
+
from .bip32_keys import Bip32PublicKey
|
|
30
|
+
from .kholaw.bip32_kholaw_key_derivator_base import Bip32KholawEd25519KeyDerivatorBase
|
|
31
|
+
from bip_utils.ecc import Ed25519KholawPrivateKey, EllipticCurve, IPoint
|
|
32
|
+
from ..utils.misc import BytesUtils, IntegerUtils
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class Bip32KholawEd25519KeyDerivator(Bip32KholawEd25519KeyDerivatorBase):
|
|
36
|
+
"""
|
|
37
|
+
BIP32 Khovratovich/Law ed25519 key derivator class.
|
|
38
|
+
It allows keys derivation for ed25519 curves in according to BIP32 Khovratovich/Law.
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
@staticmethod
|
|
42
|
+
def _SerializeIndex(index: Bip32KeyIndex) -> bytes:
|
|
43
|
+
"""
|
|
44
|
+
Serialize key index.
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
index (Bip32KeyIndex object): Key index
|
|
48
|
+
|
|
49
|
+
Returns:
|
|
50
|
+
bytes: Serialized index
|
|
51
|
+
"""
|
|
52
|
+
return index.ToBytes(endianness="little")
|
|
53
|
+
|
|
54
|
+
@staticmethod
|
|
55
|
+
def _NewPrivateKeyLeftPart(zl_bytes: bytes,
|
|
56
|
+
kl_bytes: bytes,
|
|
57
|
+
curve: EllipticCurve) -> bytes:
|
|
58
|
+
"""
|
|
59
|
+
Compute the new private key left part for private derivation.
|
|
60
|
+
|
|
61
|
+
Args:
|
|
62
|
+
zl_bytes (bytes) : Leftmost Z 32-byte
|
|
63
|
+
kl_bytes (bytes) : Leftmost private key 32-byte
|
|
64
|
+
curve (EllipticCurve object): EllipticCurve object
|
|
65
|
+
|
|
66
|
+
Returns:
|
|
67
|
+
bytes: Leftmost new private key 32-byte
|
|
68
|
+
"""
|
|
69
|
+
zl_int = BytesUtils.ToInteger(zl_bytes[:28], endianness="little")
|
|
70
|
+
kl_int = BytesUtils.ToInteger(kl_bytes, endianness="little")
|
|
71
|
+
|
|
72
|
+
prvl_int = (zl_int * 8) + kl_int
|
|
73
|
+
# Discard child if multiple of curve order
|
|
74
|
+
if prvl_int % curve.Order() == 0:
|
|
75
|
+
raise Bip32KeyError("Computed child key is not valid, very unlucky index")
|
|
76
|
+
|
|
77
|
+
return IntegerUtils.ToBytes(prvl_int,
|
|
78
|
+
bytes_num=Ed25519KholawPrivateKey.Length() // 2,
|
|
79
|
+
endianness="little")
|
|
80
|
+
|
|
81
|
+
@staticmethod
|
|
82
|
+
def _NewPrivateKeyRightPart(zr_bytes: bytes,
|
|
83
|
+
kr_bytes: bytes) -> bytes:
|
|
84
|
+
"""
|
|
85
|
+
Compute the new private key right part for private derivation.
|
|
86
|
+
|
|
87
|
+
Args:
|
|
88
|
+
zr_bytes (bytes): Rightmost Z 32-byte
|
|
89
|
+
kr_bytes (bytes): Rightmost private key 32-byte
|
|
90
|
+
|
|
91
|
+
Returns:
|
|
92
|
+
bytes: Rightmost new private key 32-byte
|
|
93
|
+
"""
|
|
94
|
+
zr_int = BytesUtils.ToInteger(zr_bytes, endianness="little")
|
|
95
|
+
kpr_int = BytesUtils.ToInteger(kr_bytes, endianness="little")
|
|
96
|
+
kr_int = (zr_int + kpr_int) % (2 ** 256)
|
|
97
|
+
|
|
98
|
+
return IntegerUtils.ToBytes(kr_int,
|
|
99
|
+
bytes_num=Ed25519KholawPrivateKey.Length() // 2,
|
|
100
|
+
endianness="little")
|
|
101
|
+
|
|
102
|
+
@staticmethod
|
|
103
|
+
def _NewPublicKeyPoint(pub_key: Bip32PublicKey,
|
|
104
|
+
zl_bytes: bytes) -> IPoint:
|
|
105
|
+
"""
|
|
106
|
+
Compute new public key point for public derivation.
|
|
107
|
+
|
|
108
|
+
Args:
|
|
109
|
+
pub_key (Bip32PublicKey object): Bip32PublicKey object
|
|
110
|
+
zl_bytes (bytes) : Leftmost Z 32-byte
|
|
111
|
+
|
|
112
|
+
Returns:
|
|
113
|
+
IPoint object: IPoint object
|
|
114
|
+
"""
|
|
115
|
+
|
|
116
|
+
# Compute the new public key point: PKEY + 8ZL * G
|
|
117
|
+
zl_int = BytesUtils.ToInteger(zl_bytes[:28], endianness="little")
|
|
118
|
+
return pub_key.Point() + ((zl_int * 8) * pub_key.Curve().Generator())
|
|
@@ -0,0 +1,204 @@
|
|
|
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
|
+
"""
|
|
22
|
+
Module for BIP32 Khovratovich/Law keys derivation (base).
|
|
23
|
+
Reference: https://github.com/LedgerHQ/orakolo/blob/master/papers/Ed25519_BIP%20Final.pdf
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
# Imports
|
|
27
|
+
from abc import ABC, abstractmethod
|
|
28
|
+
from typing import Tuple, Union
|
|
29
|
+
|
|
30
|
+
from .base import IBip32KeyDerivator
|
|
31
|
+
from .bip32_ex import Bip32KeyError
|
|
32
|
+
from .bip32_key_data import Bip32KeyIndex
|
|
33
|
+
from .bip32_keys import Bip32PrivateKey, Bip32PublicKey
|
|
34
|
+
from bip_utils.ecc import EllipticCurve, IPoint
|
|
35
|
+
from ..utils.crypto import HmacSha512
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class Bip32KholawEd25519KeyDerivatorBase(IBip32KeyDerivator, ABC):
|
|
39
|
+
"""
|
|
40
|
+
BIP32 Khovratovich/Law ed25519 key derivator base class.
|
|
41
|
+
It allows keys derivation for ed25519 curves in according to BIP32 Khovratovich/Law.
|
|
42
|
+
It shall be inherited by child classes to customize the derivation algorithm.
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
@staticmethod
|
|
46
|
+
def IsPublicDerivationSupported() -> bool:
|
|
47
|
+
"""
|
|
48
|
+
Get if public derivation is supported.
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
bool: True if supported, false otherwise.
|
|
52
|
+
"""
|
|
53
|
+
return True
|
|
54
|
+
|
|
55
|
+
@classmethod
|
|
56
|
+
def CkdPriv(cls,
|
|
57
|
+
priv_key: Bip32PrivateKey,
|
|
58
|
+
pub_key: Bip32PublicKey,
|
|
59
|
+
index: Bip32KeyIndex) -> Tuple[bytes, bytes]:
|
|
60
|
+
"""
|
|
61
|
+
Derive a child key with the specified index using private derivation.
|
|
62
|
+
|
|
63
|
+
Args:
|
|
64
|
+
priv_key (Bip32PrivateKey object): Bip32PrivateKey object
|
|
65
|
+
pub_key (Bip32PublicKey object) : Bip32PublicKey object
|
|
66
|
+
index (Bip32KeyIndex object) : Key index
|
|
67
|
+
|
|
68
|
+
Returns:
|
|
69
|
+
tuple[bytes, bytes]: Private key bytes (index 0) and chain code bytes (index 1)
|
|
70
|
+
|
|
71
|
+
Raises:
|
|
72
|
+
Bip32KeyError: If the index results in an invalid key
|
|
73
|
+
"""
|
|
74
|
+
|
|
75
|
+
# Get index and key bytes
|
|
76
|
+
index_bytes = cls._SerializeIndex(index)
|
|
77
|
+
chain_code_bytes = priv_key.ChainCode().ToBytes()
|
|
78
|
+
priv_key_bytes = priv_key.Raw().ToBytes()
|
|
79
|
+
pub_key_bytes = pub_key.RawCompressed().ToBytes()[1:]
|
|
80
|
+
|
|
81
|
+
# Compute Z and chain code
|
|
82
|
+
if index.IsHardened():
|
|
83
|
+
z_bytes = HmacSha512.QuickDigest(chain_code_bytes,
|
|
84
|
+
b"\x00" + priv_key_bytes + index_bytes)
|
|
85
|
+
chain_code_bytes = HmacSha512.QuickDigestHalves(chain_code_bytes,
|
|
86
|
+
b"\x01" + priv_key_bytes + index_bytes)[1]
|
|
87
|
+
else:
|
|
88
|
+
z_bytes = HmacSha512.QuickDigest(chain_code_bytes,
|
|
89
|
+
b"\x02" + pub_key_bytes + index_bytes)
|
|
90
|
+
chain_code_bytes = HmacSha512.QuickDigestHalves(chain_code_bytes,
|
|
91
|
+
b"\x03" + pub_key_bytes + index_bytes)[1]
|
|
92
|
+
|
|
93
|
+
# Compute the left and right part of the new private key
|
|
94
|
+
hmac_half_len = HmacSha512.DigestSize() // 2
|
|
95
|
+
kl_bytes = cls._NewPrivateKeyLeftPart(z_bytes[:hmac_half_len],
|
|
96
|
+
priv_key_bytes[:hmac_half_len],
|
|
97
|
+
pub_key.Curve())
|
|
98
|
+
kr_bytes = cls._NewPrivateKeyRightPart(z_bytes[hmac_half_len:],
|
|
99
|
+
priv_key_bytes[hmac_half_len:])
|
|
100
|
+
|
|
101
|
+
return kl_bytes + kr_bytes, chain_code_bytes
|
|
102
|
+
|
|
103
|
+
@classmethod
|
|
104
|
+
def CkdPub(cls,
|
|
105
|
+
pub_key: Bip32PublicKey,
|
|
106
|
+
index: Bip32KeyIndex) -> Tuple[Union[bytes, IPoint], bytes]:
|
|
107
|
+
"""
|
|
108
|
+
Derive a child key with the specified index using public derivation.
|
|
109
|
+
|
|
110
|
+
Args:
|
|
111
|
+
pub_key (Bip32PublicKey object): Bip32PublicKey object
|
|
112
|
+
index (Bip32KeyIndex object) : Key index
|
|
113
|
+
|
|
114
|
+
Returns:
|
|
115
|
+
tuple[bytes or IPoint, bytes]: Public key bytes or point (index 0) and chain code bytes (index 1)
|
|
116
|
+
|
|
117
|
+
Raises:
|
|
118
|
+
Bip32KeyError: If the index results in an invalid key
|
|
119
|
+
"""
|
|
120
|
+
|
|
121
|
+
# Get index and key bytes
|
|
122
|
+
index_bytes = cls._SerializeIndex(index)
|
|
123
|
+
chain_code_bytes = pub_key.ChainCode().ToBytes()
|
|
124
|
+
pub_key_bytes = pub_key.RawCompressed().ToBytes()[1:]
|
|
125
|
+
|
|
126
|
+
# Compute Z and chain code
|
|
127
|
+
z_bytes = HmacSha512.QuickDigest(chain_code_bytes,
|
|
128
|
+
b"\x02" + pub_key_bytes + index_bytes)
|
|
129
|
+
chain_code_bytes = HmacSha512.QuickDigestHalves(chain_code_bytes,
|
|
130
|
+
b"\x03" + pub_key_bytes + index_bytes)[1]
|
|
131
|
+
|
|
132
|
+
# Compute the new public key point
|
|
133
|
+
hmac_half_len = HmacSha512.DigestSize() // 2
|
|
134
|
+
new_pub_key_point = cls._NewPublicKeyPoint(pub_key,
|
|
135
|
+
z_bytes[:hmac_half_len])
|
|
136
|
+
# If the public key is the identity point (0, 1) discard the child
|
|
137
|
+
if new_pub_key_point.X() == 0 and new_pub_key_point.Y() == 1:
|
|
138
|
+
raise Bip32KeyError("Computed public child key is not valid, very unlucky index")
|
|
139
|
+
|
|
140
|
+
return new_pub_key_point, chain_code_bytes
|
|
141
|
+
|
|
142
|
+
#
|
|
143
|
+
# Abstract methods
|
|
144
|
+
#
|
|
145
|
+
|
|
146
|
+
@staticmethod
|
|
147
|
+
@abstractmethod
|
|
148
|
+
def _SerializeIndex(index: Bip32KeyIndex) -> bytes:
|
|
149
|
+
"""
|
|
150
|
+
Serialize key index.
|
|
151
|
+
|
|
152
|
+
Args:
|
|
153
|
+
index (Bip32KeyIndex object): Key index
|
|
154
|
+
|
|
155
|
+
Returns:
|
|
156
|
+
bytes: Serialized index
|
|
157
|
+
"""
|
|
158
|
+
|
|
159
|
+
@staticmethod
|
|
160
|
+
@abstractmethod
|
|
161
|
+
def _NewPrivateKeyLeftPart(zl_bytes: bytes,
|
|
162
|
+
kl_bytes: bytes,
|
|
163
|
+
curve: EllipticCurve) -> bytes:
|
|
164
|
+
"""
|
|
165
|
+
Compute the new private key left part for private derivation.
|
|
166
|
+
|
|
167
|
+
Args:
|
|
168
|
+
zl_bytes (bytes) : Leftmost Z 32-byte
|
|
169
|
+
kl_bytes (bytes) : Leftmost private key 32-byte
|
|
170
|
+
curve (EllipticCurve object): EllipticCurve object
|
|
171
|
+
|
|
172
|
+
Returns:
|
|
173
|
+
bytes: Leftmost new private key 32-byte
|
|
174
|
+
"""
|
|
175
|
+
|
|
176
|
+
@staticmethod
|
|
177
|
+
@abstractmethod
|
|
178
|
+
def _NewPrivateKeyRightPart(zr_bytes: bytes,
|
|
179
|
+
kr_bytes: bytes) -> bytes:
|
|
180
|
+
"""
|
|
181
|
+
Compute the new private key right part for private derivation.
|
|
182
|
+
|
|
183
|
+
Args:
|
|
184
|
+
zr_bytes (bytes): Rightmost Z 32-byte
|
|
185
|
+
kr_bytes (bytes): Rightmost private key 32-byte
|
|
186
|
+
|
|
187
|
+
Returns:
|
|
188
|
+
bytes: Rightmost new private key 32-byte
|
|
189
|
+
"""
|
|
190
|
+
|
|
191
|
+
@staticmethod
|
|
192
|
+
@abstractmethod
|
|
193
|
+
def _NewPublicKeyPoint(pub_key: Bip32PublicKey,
|
|
194
|
+
zl_bytes: bytes) -> IPoint:
|
|
195
|
+
"""
|
|
196
|
+
Compute new public key point for public derivation.
|
|
197
|
+
|
|
198
|
+
Args:
|
|
199
|
+
pub_key (Bip32PublicKey object): Bip32PublicKey object
|
|
200
|
+
zl_bytes (bytes) : Leftmost Z 32-byte
|
|
201
|
+
|
|
202
|
+
Returns:
|
|
203
|
+
IPoint object: IPoint object
|
|
204
|
+
"""
|
|
@@ -0,0 +1,119 @@
|
|
|
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
|
+
"""
|
|
22
|
+
Module for BIP32 Khovratovich/Law master key generation.
|
|
23
|
+
Reference: https://github.com/LedgerHQ/orakolo/blob/master/papers/Ed25519_BIP%20Final.pdf
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
# Imports
|
|
27
|
+
from typing import Tuple
|
|
28
|
+
|
|
29
|
+
from .base import IBip32MstKeyGenerator
|
|
30
|
+
from .slip10.bip32_slip10_mst_key_generator import Bip32Slip10MstKeyGeneratorConst
|
|
31
|
+
from ..utils.crypto import HmacSha256, HmacSha512
|
|
32
|
+
from ..utils.misc import BitUtils
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class Bip32KholawMstKeyGeneratorConst:
|
|
36
|
+
"""Class container for BIP32 Khovratovich/Law master key generator constants."""
|
|
37
|
+
|
|
38
|
+
# Minimum length in bytes for seed
|
|
39
|
+
SEED_MIN_BYTE_LEN: int = Bip32Slip10MstKeyGeneratorConst.SEED_MIN_BYTE_LEN
|
|
40
|
+
# HMAC key for generating master key
|
|
41
|
+
MASTER_KEY_HMAC_KEY: bytes = Bip32Slip10MstKeyGeneratorConst.HMAC_KEY_ED25519_BYTES
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class Bip32KholawEd25519MstKeyGenerator(IBip32MstKeyGenerator):
|
|
45
|
+
"""
|
|
46
|
+
BIP32 Khovratovich/Law ed25519 master key generator class.
|
|
47
|
+
It allows master keys generation in according to BIP32 Khovratovich/Law for ed25519 curve.
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
@classmethod
|
|
51
|
+
def GenerateFromSeed(cls,
|
|
52
|
+
seed_bytes: bytes) -> Tuple[bytes, bytes]:
|
|
53
|
+
"""
|
|
54
|
+
Generate a master key from the specified seed.
|
|
55
|
+
|
|
56
|
+
Args:
|
|
57
|
+
seed_bytes (bytes): Seed bytes
|
|
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 seed is not suitable for master key generation
|
|
64
|
+
ValueError: If seed length is not valid
|
|
65
|
+
"""
|
|
66
|
+
if len(seed_bytes) < Bip32KholawMstKeyGeneratorConst.SEED_MIN_BYTE_LEN:
|
|
67
|
+
raise ValueError(f"Invalid seed length ({len(seed_bytes)})")
|
|
68
|
+
|
|
69
|
+
# Compute kL and kR
|
|
70
|
+
kl_bytes, kr_bytes = cls.__HashRepeatedly(seed_bytes, Bip32KholawMstKeyGeneratorConst.MASTER_KEY_HMAC_KEY)
|
|
71
|
+
# Tweak kL bytes
|
|
72
|
+
kl_bytes = cls.__TweakMasterKeyBits(kl_bytes)
|
|
73
|
+
|
|
74
|
+
# Compute chain code
|
|
75
|
+
chain_code_bytes = HmacSha256.QuickDigest(Bip32KholawMstKeyGeneratorConst.MASTER_KEY_HMAC_KEY,
|
|
76
|
+
b"\x01" + seed_bytes)
|
|
77
|
+
|
|
78
|
+
return kl_bytes + kr_bytes, chain_code_bytes
|
|
79
|
+
|
|
80
|
+
@classmethod
|
|
81
|
+
def __HashRepeatedly(cls,
|
|
82
|
+
data_bytes: bytes,
|
|
83
|
+
hmac_key_bytes: bytes) -> Tuple[bytes, bytes]:
|
|
84
|
+
"""
|
|
85
|
+
Continue to hash the data bytes until the third-highest bit of the last byte is not zero.
|
|
86
|
+
|
|
87
|
+
Args:
|
|
88
|
+
data_bytes (bytes) : Data bytes
|
|
89
|
+
hmac_key_bytes (bytes): HMAC key bytes
|
|
90
|
+
|
|
91
|
+
Returns:
|
|
92
|
+
tuple[bytes, bytes]: Two halves of the computed hash
|
|
93
|
+
"""
|
|
94
|
+
kl_bytes, kr_bytes = HmacSha512.QuickDigestHalves(hmac_key_bytes,
|
|
95
|
+
data_bytes)
|
|
96
|
+
if BitUtils.AreBitsSet(kl_bytes[31], 0x20):
|
|
97
|
+
return cls.__HashRepeatedly(kl_bytes + kr_bytes, hmac_key_bytes)
|
|
98
|
+
return kl_bytes, kr_bytes
|
|
99
|
+
|
|
100
|
+
@staticmethod
|
|
101
|
+
def __TweakMasterKeyBits(key_bytes: bytes) -> bytes:
|
|
102
|
+
"""
|
|
103
|
+
Tweak master key bits.
|
|
104
|
+
|
|
105
|
+
Args:
|
|
106
|
+
key_bytes (bytes): Key bytes
|
|
107
|
+
|
|
108
|
+
Returns:
|
|
109
|
+
bytes: Tweaked key bytes
|
|
110
|
+
"""
|
|
111
|
+
key_bytes = bytearray(key_bytes)
|
|
112
|
+
# Clear the lowest 3 bits of the first byte of kL
|
|
113
|
+
key_bytes[0] = BitUtils.ResetBits(key_bytes[0], 0x07)
|
|
114
|
+
# Clear the highest bit of the last byte of kL
|
|
115
|
+
key_bytes[31] = BitUtils.ResetBits(key_bytes[31], 0x80)
|
|
116
|
+
# Set the second-highest bit of the last byte of kL
|
|
117
|
+
key_bytes[31] = BitUtils.SetBits(key_bytes[31], 0x40)
|
|
118
|
+
|
|
119
|
+
return bytes(key_bytes)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .bip32_slip10_secp256k1 import Bip32Secp256k1, Bip32Slip10Secp256k1
|