libcrypto 1.0.1__py3-none-any.whl → 1.1.3__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.
- libcrypto/__init__.py +1 -1
- libcrypto-1.1.3.dist-info/METADATA +225 -0
- {libcrypto-1.0.1.dist-info → libcrypto-1.1.3.dist-info}/RECORD +7 -7
- libcrypto-1.0.1.dist-info/METADATA +0 -318
- {libcrypto-1.0.1.dist-info → libcrypto-1.1.3.dist-info}/WHEEL +0 -0
- {libcrypto-1.0.1.dist-info → libcrypto-1.1.3.dist-info}/entry_points.txt +0 -0
- {libcrypto-1.0.1.dist-info → libcrypto-1.1.3.dist-info}/licenses/LICENSE +0 -0
- {libcrypto-1.0.1.dist-info → libcrypto-1.1.3.dist-info}/top_level.txt +0 -0
libcrypto/__init__.py
CHANGED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: libcrypto
|
|
3
|
+
Version: 1.1.3
|
|
4
|
+
Summary: A professional library For Cryptography and Cryptocurrencies in Python.
|
|
5
|
+
Home-page: https://github.com/pymmdrza/libcrypto
|
|
6
|
+
Author: Mmdrza
|
|
7
|
+
Author-email: Mmdrza <pymmdrza@gmail.com>
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Homepage, https://libcrypto.readthedocs.io/
|
|
10
|
+
Project-URL: Repository, https://github.com/Pymmdrza/libcrypto
|
|
11
|
+
Project-URL: Bug Tracker, https://github.com/Pymmdrza/libcrypto/issues
|
|
12
|
+
Project-URL: Documentation, https://libcrypto.readthedocs.io
|
|
13
|
+
Project-URL: PyPI, https://pypi.org/project/libcrypto/
|
|
14
|
+
Keywords: cryptocurrency,bitcoin,ethereum,wallet,bip39,bip32,bip44,mnemonic,private-key,public-key,address,hdwallet,crypto,blockchain,litecoin,dash,dogecoin,bitcoin-cash,secp256k1,pycryptodome,cryptography
|
|
15
|
+
Classifier: Development Status :: 4 - Beta
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
25
|
+
Classifier: Topic :: Security :: Cryptography
|
|
26
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
27
|
+
Classifier: Topic :: Office/Business :: Financial
|
|
28
|
+
Classifier: Topic :: System :: Systems Administration :: Authentication/Directory
|
|
29
|
+
Classifier: Typing :: Typed
|
|
30
|
+
Requires-Python: >=3.8
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
License-File: LICENSE
|
|
33
|
+
Requires-Dist: pycryptodome>=3.23.0
|
|
34
|
+
Requires-Dist: rich>=14.0.0
|
|
35
|
+
Requires-Dist: wheel>=0.45.1
|
|
36
|
+
Requires-Dist: setuptools>=80.9.0
|
|
37
|
+
Provides-Extra: dev
|
|
38
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
39
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
40
|
+
Requires-Dist: black>=22.0.0; extra == "dev"
|
|
41
|
+
Requires-Dist: flake8>=5.0.0; extra == "dev"
|
|
42
|
+
Requires-Dist: isort>=5.10.0; extra == "dev"
|
|
43
|
+
Requires-Dist: mypy>=1.0.0; extra == "dev"
|
|
44
|
+
Provides-Extra: test
|
|
45
|
+
Requires-Dist: pytest>=7.0.0; extra == "test"
|
|
46
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "test"
|
|
47
|
+
Dynamic: author
|
|
48
|
+
Dynamic: home-page
|
|
49
|
+
Dynamic: license-file
|
|
50
|
+
Dynamic: requires-python
|
|
51
|
+
|
|
52
|
+
[](https://pypi.org/project/libcrypto/)
|
|
53
|
+
[](LICENSE)
|
|
54
|
+
|
|
55
|
+
# LibCrypto
|
|
56
|
+
|
|
57
|
+
A professional library for Cryptography and Cryptocurrencies in Python.
|
|
58
|
+
|
|
59
|
+
This library provides a comprehensive suite of tools for developers working with cryptocurrencies, focusing on key management and address generation with a clean, high-level API.
|
|
60
|
+
|
|
61
|
+
## Key Features
|
|
62
|
+
|
|
63
|
+
- **High-Level Wallet API**: A simple `Wallet` class to manage keys and addresses.
|
|
64
|
+
- **Multi-Currency Support**: Correctly generate addresses for numerous secp256k1-based cryptocurrencies, including:
|
|
65
|
+
- Bitcoin (BTC) - Legacy, SegWit (P2SH & Native)
|
|
66
|
+
- Ethereum (ETH)
|
|
67
|
+
- Tron (TRX)
|
|
68
|
+
- Ripple (XRP)
|
|
69
|
+
- Bitcoin Cash (BCH) - CashAddr format
|
|
70
|
+
- Litecoin (LTC)
|
|
71
|
+
- Dash (DASH)
|
|
72
|
+
- Dogecoin (DOGE)
|
|
73
|
+
- **Hierarchical Deterministic (HD) Wallets**: Full BIP32 support for generating wallets from a master seed.
|
|
74
|
+
- **BIP39 Mnemonic Support**: Generate, validate, and derive seeds from mnemonic phrases.
|
|
75
|
+
- **Key & Format Conversions**: Easily convert between WIF, Hex, and Bytes for private and public keys.
|
|
76
|
+
- **Powerful Command-Line Interface**: Perform common wallet operations directly from your terminal.
|
|
77
|
+
|
|
78
|
+
## Installation
|
|
79
|
+
|
|
80
|
+
Install the library using pip:
|
|
81
|
+
```bash
|
|
82
|
+
pip install libcrypto
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Quick Start (Library Usage)
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
from libcrypto import Wallet
|
|
89
|
+
|
|
90
|
+
key = "Your private key here (hex)"
|
|
91
|
+
# Initialize the Wallet with the private key
|
|
92
|
+
# Replace "Your private key here (hex)" with your actual private key in hexadecimal format
|
|
93
|
+
wallet = Wallet(key)
|
|
94
|
+
# Generate P2PKH, P2SH-P2WPKH, P2WPKH addresses for Bitcoin
|
|
95
|
+
p2pkh = wallet.get_address(coin="bitcoin", address_type="p2pkh")
|
|
96
|
+
p2wsh = wallet.get_address(coin="bitcoin", address_type="p2sh-p2wpkh")
|
|
97
|
+
p2wpkh = wallet.get_address(coin="bitcoin", address_type="p2wpkh")
|
|
98
|
+
# Generate ethereum Address
|
|
99
|
+
ethereum_address = wallet.get_address(coin="ethereum")
|
|
100
|
+
# Generate Dash Address
|
|
101
|
+
dash = wallet.get_address(coin="dash")
|
|
102
|
+
# Generate Dogecoin Address
|
|
103
|
+
dogecoin_address = wallet.get_address(coin="dogecoin")
|
|
104
|
+
# Generate Tron Address
|
|
105
|
+
tron_address = wallet.get_address(coin="tron")
|
|
106
|
+
# Generate Ripple Address
|
|
107
|
+
ripple_address = wallet.get_address(coin="ripple")
|
|
108
|
+
# Generate Litecoin Address
|
|
109
|
+
litecoin_address = wallet.get_address(coin="litecoin")
|
|
110
|
+
# Generate Litecoin Address with specific address types
|
|
111
|
+
litecoin_address_p2pkh = wallet.get_address(coin="litecoin", address_type="p2pkh")
|
|
112
|
+
litecoin_address_p2wsh = wallet.get_address(coin="litecoin", address_type="p2sh-p2wpkh")
|
|
113
|
+
litecoin_address_p2wpkh = wallet.get_address(coin="litecoin", address_type="p2wpkh")
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
The library is designed to be straightforward. Here is a basic example of generating addresses from an existing private key.
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
from libcrypto import Wallet
|
|
120
|
+
|
|
121
|
+
# Initialize a wallet from a WIF private key
|
|
122
|
+
wif_key = "L4ZQks37JHUadEqaj2nGB1eaZFcsRZwZGQ7WVYuQiztzg4pqopU6" # Example WIF key
|
|
123
|
+
wallet = Wallet(wif_key)
|
|
124
|
+
|
|
125
|
+
# Generate addresses for different coins
|
|
126
|
+
eth_address = wallet.get_address('ethereum')
|
|
127
|
+
btc_address = wallet.get_address('bitcoin', address_type='p2wpkh') # Native SegWit
|
|
128
|
+
bch_address = wallet.get_address('bitcoin_cash')
|
|
129
|
+
|
|
130
|
+
print(f"Ethereum Address: {eth_address}")
|
|
131
|
+
print(f"Bitcoin (SegWit) Address: {btc_address}")
|
|
132
|
+
print(f"Bitcoin Cash Address: {bch_address}")
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+

|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
## Quick Start (Command-Line Interface)
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
# version
|
|
142
|
+
libcrypto -v
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Package Information:
|
|
146
|
+
```bash
|
|
147
|
+
libcrypto info
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Wallet & Address Generation
|
|
151
|
+
- Generate a Wallet:
|
|
152
|
+
This is the main command for generating new wallets or deriving addresses from existing keys.
|
|
153
|
+
```bash
|
|
154
|
+
libcrypto generate [OPTIONS]
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Options:
|
|
158
|
+
|
|
159
|
+
- `-p`, `--private-key` TEXT: Derive addresses from an existing private key (WIF or Hex format). If omitted, a new random wallet is generated.
|
|
160
|
+
- `-c`, `--coin` TEXT: Specify a coin to generate addresses for. This option can be used multiple times. Defaults to bitcoin and ethereum.
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
1. Generate a new wallet for Bitcoin and Litecoin:
|
|
164
|
+
```bash
|
|
165
|
+
libcrypto generate -c bitcoin -c litecoin
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
2. Generate a wallet from an existing private key:
|
|
169
|
+
```bash
|
|
170
|
+
libcrypto generate -p <your-private-key>
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
3. Derive addresses for a specific set of coins from a hex key:
|
|
174
|
+
```bash
|
|
175
|
+
libcrypto generate -p <your-hex-key> -c bitcoin -c ethereum -c dash -c tron
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Mnemonic Management
|
|
179
|
+
|
|
180
|
+
The mnemonic subcommand is used for all BIP39 mnemonic phrase operations.
|
|
181
|
+
Generate a Mnemonic Phrase
|
|
182
|
+
|
|
183
|
+
Creates a new, cryptographically secure BIP39 mnemonic phrase.
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
libcrypto mnemonic generate [OPTIONS]
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Options:
|
|
190
|
+
|
|
191
|
+
- `-w`, `--words` INTEGER: The number of words in the mnemonic. Can be 12, 15, 18, 21, or 24. [Default: 12]
|
|
192
|
+
|
|
193
|
+
Example:
|
|
194
|
+
```bash
|
|
195
|
+
libcrypto mnemonic generate --words 24
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Validate a Mnemonic Phrase
|
|
199
|
+
|
|
200
|
+
Checks if a given BIP39 mnemonic phrase is valid according to the checksum rules.
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
libcrypto mnemonic validate "PHRASE"
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Arguments:
|
|
207
|
+
|
|
208
|
+
- `PHRASE`: The full mnemonic phrase, enclosed in double quotes. [Required]
|
|
209
|
+
|
|
210
|
+
Example:
|
|
211
|
+
```bash
|
|
212
|
+
libcrypto mnemonic validate "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
## Donate
|
|
216
|
+
|
|
217
|
+
If you find this library useful, consider supporting its development:
|
|
218
|
+
|
|
219
|
+
- **Bitcoin (BTC)**: `1MMDRZAcM6dzmdMUSV8pDdAPDFpwzve9Fc`
|
|
220
|
+
|
|
221
|
+
## Contact
|
|
222
|
+
|
|
223
|
+
For support or inquiries, please contact us at [pymmdrza@gmail.com](mailto:pymmdrza@gmail.com).
|
|
224
|
+
|
|
225
|
+
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
libcrypto/__init__.py,sha256=
|
|
1
|
+
libcrypto/__init__.py,sha256=pHnzYRNXMhpcvApXHAUXnLP8gz8ruKUgtnCYuku25Fs,1520
|
|
2
2
|
libcrypto/_version.py,sha256=DSDyLW2lPzd96MgdTJ1v2YoJcpnh3k-GDDmngzKiFdA,485
|
|
3
3
|
libcrypto/addresses.py,sha256=_rwJbuIJA9Pt-mD7SpEHoUCyNlC0ghXURLI71ZDKTJA,7491
|
|
4
4
|
libcrypto/bip32.py,sha256=uzhd0l9FPgNRWzpfhcpZedyJo48y6UrrB_1cPVeoW7E,8466
|
|
@@ -10,9 +10,9 @@ libcrypto/keys.py,sha256=_HIoHrGcoHTqJ2qQsZroTHEexyLIM5Mn5t9eMMMdqP4,5051
|
|
|
10
10
|
libcrypto/mnemonic.py,sha256=cmHFX1B4YGGN3pIaFDuffrpKKkTCAXya5W58oA77KBk,4677
|
|
11
11
|
libcrypto/secp256k1.py,sha256=4FH_byTr2fXms4q3BtSHVBs-4NPE2gyDaS_lS4oeDWw,3873
|
|
12
12
|
libcrypto/wallet.py,sha256=LWjhwKe7nKonB6oaKOggMdPstIrXYKJhJcYPCcKqU6c,5835
|
|
13
|
-
libcrypto-1.
|
|
14
|
-
libcrypto-1.
|
|
15
|
-
libcrypto-1.
|
|
16
|
-
libcrypto-1.
|
|
17
|
-
libcrypto-1.
|
|
18
|
-
libcrypto-1.
|
|
13
|
+
libcrypto-1.1.3.dist-info/licenses/LICENSE,sha256=VmwUVixn0u8rR_TF0dIoqv7CK0a5WBoFX8zQvIYa4eE,1071
|
|
14
|
+
libcrypto-1.1.3.dist-info/METADATA,sha256=Qd2WfCUb1_zmQZWlJAnnxG_llX3fSoZ39BSOibVzB8E,7756
|
|
15
|
+
libcrypto-1.1.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
16
|
+
libcrypto-1.1.3.dist-info/entry_points.txt,sha256=P1JmZQ0W2Mi9rD37f9yFG2hYxGInDUY9i9erY_hldTY,48
|
|
17
|
+
libcrypto-1.1.3.dist-info/top_level.txt,sha256=CP4_HN2d5lfT-Jo0IQgNdbGYjk4PSDHK0EU4xfaKmGc,10
|
|
18
|
+
libcrypto-1.1.3.dist-info/RECORD,,
|
|
@@ -1,318 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: libcrypto
|
|
3
|
-
Version: 1.0.1
|
|
4
|
-
Summary: A professional library For Cryptography and Cryptocurrencies in Python.
|
|
5
|
-
Home-page: https://github.com/pymmdrza/libcrypto
|
|
6
|
-
Author: Mmdrza
|
|
7
|
-
Author-email: Mmdrza <pymmdrza@gmail.com>
|
|
8
|
-
License: MIT
|
|
9
|
-
Project-URL: Homepage, https://libcrypto.readthedocs.io/
|
|
10
|
-
Project-URL: Repository, https://github.com/Pymmdrza/libcrypto
|
|
11
|
-
Project-URL: Bug Tracker, https://github.com/Pymmdrza/libcrypto/issues
|
|
12
|
-
Classifier: Programming Language :: Python :: 3
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
18
|
-
Classifier: Operating System :: OS Independent
|
|
19
|
-
Classifier: Intended Audience :: Developers
|
|
20
|
-
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
-
Classifier: Topic :: Security :: Cryptography
|
|
22
|
-
Requires-Python: >=3.8
|
|
23
|
-
Description-Content-Type: text/markdown
|
|
24
|
-
License-File: LICENSE
|
|
25
|
-
Requires-Dist: pycryptodome
|
|
26
|
-
Requires-Dist: ecdsa
|
|
27
|
-
Requires-Dist: rich
|
|
28
|
-
Requires-Dist: typer
|
|
29
|
-
Dynamic: author
|
|
30
|
-
Dynamic: home-page
|
|
31
|
-
Dynamic: license-file
|
|
32
|
-
Dynamic: requires-python
|
|
33
|
-
|
|
34
|
-
# LibCrypto - Cryptocurrency Wallet Library
|
|
35
|
-
|
|
36
|
-
A comprehensive, self-contained Python cryptocurrency wallet library that provides all necessary tools for generating and managing cryptocurrency wallet keys and addresses **without any external dependencies**.
|
|
37
|
-
|
|
38
|
-
## 🚀 Features
|
|
39
|
-
|
|
40
|
-
### Core Functionality
|
|
41
|
-
- **BIP39 Mnemonic Phrases**: Generate and validate secure mnemonic phrases (12, 15, 18, 21, 24 words)
|
|
42
|
-
- **BIP32 HD Wallets**: Hierarchical deterministic wallet support with full BIP44 compliance
|
|
43
|
-
- **Multi-Currency Support**: Generate addresses for 13+ cryptocurrencies
|
|
44
|
-
- **Key Format Conversions**: Convert between hex, WIF, bytes, decimal, and mnemonic formats
|
|
45
|
-
- **Zero Dependencies**: Uses only Python standard library and included C extensions
|
|
46
|
-
|
|
47
|
-
### Supported Cryptocurrencies
|
|
48
|
-
- **Bitcoin (BTC)** - P2PKH, P2SH, P2WPKH, P2WSH (SegWit)
|
|
49
|
-
- **Ethereum (ETH)** - Native addresses with EIP-55 checksum
|
|
50
|
-
- **Litecoin (LTC)** - All Bitcoin-compatible formats
|
|
51
|
-
- **Bitcoin Cash (BCH)** - Legacy and CashAddr formats
|
|
52
|
-
- **Bitcoin Gold (BTG)** - All standard formats
|
|
53
|
-
- **Dogecoin (DOGE)** - P2PKH and P2SH
|
|
54
|
-
- **Dash** - P2PKH and P2SH
|
|
55
|
-
- **Digibyte (DGB)** - All standard formats
|
|
56
|
-
- **Zcash (ZEC)** - T-addresses
|
|
57
|
-
- **Tron (TRX)** - Native TRX addresses
|
|
58
|
-
- **Solana (SOL)** - Base58 encoded addresses
|
|
59
|
-
- **Avalanche (AVAX)** - C-Chain addresses
|
|
60
|
-
- **TON** - Native TON addresses
|
|
61
|
-
- **Ripple (XRP)** - Classic addresses
|
|
62
|
-
|
|
63
|
-
### Address Formats
|
|
64
|
-
- **P2PKH**: Pay to Public Key Hash (1...)
|
|
65
|
-
- **P2SH**: Pay to Script Hash (3...)
|
|
66
|
-
- **P2WPKH**: Pay to Witness Public Key Hash (bc1...)
|
|
67
|
-
- **P2WSH**: Pay to Witness Script Hash (bc1...)
|
|
68
|
-
- **Ethereum**: Keccak256-based addresses (0x...)
|
|
69
|
-
|
|
70
|
-
## 📦 Installation
|
|
71
|
-
|
|
72
|
-
```bash
|
|
73
|
-
# Clone the repository
|
|
74
|
-
git clone <repository-url>
|
|
75
|
-
cd libcrypto
|
|
76
|
-
|
|
77
|
-
# Install in development mode
|
|
78
|
-
pip install -e .
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
## 🔧 Quick Start
|
|
82
|
-
|
|
83
|
-
### Generate a New Mnemonic and Wallet
|
|
84
|
-
|
|
85
|
-
```python
|
|
86
|
-
import mnemonic
|
|
87
|
-
from wallet import HDWallet, PrivateKey, AddressGenerator
|
|
88
|
-
|
|
89
|
-
# Generate a new 12-word mnemonic
|
|
90
|
-
new_mnemonic = mnemonic.generate_mnemonic(12)
|
|
91
|
-
print(f"Generated mnemonic: {new_mnemonic}")
|
|
92
|
-
|
|
93
|
-
# Create HD wallet from mnemonic
|
|
94
|
-
wallet = HDWallet.from_mnemonic(new_mnemonic)
|
|
95
|
-
|
|
96
|
-
# Get Bitcoin address (BIP44 path: m/44'/0'/0'/0/0)
|
|
97
|
-
btc_key = wallet.derive_address_key(coin_type=0, address_index=0)
|
|
98
|
-
btc_address = AddressGenerator.from_public_key(
|
|
99
|
-
btc_key.public_key, 'p2pkh', 'bitcoin'
|
|
100
|
-
)
|
|
101
|
-
print(f"Bitcoin address: {btc_address}")
|
|
102
|
-
|
|
103
|
-
# Get Ethereum address (BIP44 path: m/44'/60'/0'/0/0)
|
|
104
|
-
eth_key = wallet.derive_address_key(coin_type=60, address_index=0)
|
|
105
|
-
eth_address = AddressGenerator.from_public_key(
|
|
106
|
-
eth_key.public_key, 'ethereum', 'ethereum'
|
|
107
|
-
)
|
|
108
|
-
print(f"Ethereum address: {eth_address}")
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
### Import Existing Mnemonic
|
|
112
|
-
|
|
113
|
-
```python
|
|
114
|
-
import mnemonic
|
|
115
|
-
from wallet import HDWallet
|
|
116
|
-
|
|
117
|
-
# Import existing mnemonic
|
|
118
|
-
existing_mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
|
|
119
|
-
|
|
120
|
-
# Validate mnemonic
|
|
121
|
-
if mnemonic.validate_mnemonic(existing_mnemonic):
|
|
122
|
-
print("✅ Mnemonic is valid")
|
|
123
|
-
|
|
124
|
-
# Create wallet
|
|
125
|
-
wallet = HDWallet.from_mnemonic(existing_mnemonic)
|
|
126
|
-
|
|
127
|
-
# Get master keys
|
|
128
|
-
print(f"Master private key: {wallet.get_master_private_key()}")
|
|
129
|
-
print(f"Master public key: {wallet.get_master_public_key()}")
|
|
130
|
-
else:
|
|
131
|
-
print("❌ Invalid mnemonic")
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
### Private Key Operations
|
|
135
|
-
|
|
136
|
-
```python
|
|
137
|
-
from wallet import PrivateKey
|
|
138
|
-
|
|
139
|
-
# Generate a new private key
|
|
140
|
-
private_key = PrivateKey.generate()
|
|
141
|
-
|
|
142
|
-
# Convert to different formats
|
|
143
|
-
print(f"Hex: {private_key.hex}")
|
|
144
|
-
print(f"WIF: {private_key.to_wif()}")
|
|
145
|
-
print(f"Decimal: {private_key.decimal}")
|
|
146
|
-
|
|
147
|
-
# Get public key and address
|
|
148
|
-
public_key = private_key.get_public_key()
|
|
149
|
-
btc_address = public_key.get_address('p2pkh', 'bitcoin')
|
|
150
|
-
print(f"Bitcoin address: {btc_address}")
|
|
151
|
-
|
|
152
|
-
# Import from hex
|
|
153
|
-
hex_key = "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"
|
|
154
|
-
imported_key = PrivateKey.from_hex(hex_key)
|
|
155
|
-
print(f"Imported key WIF: {imported_key.to_wif()}")
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
### Multiple Address Generation
|
|
159
|
-
|
|
160
|
-
```python
|
|
161
|
-
from wallet import HDWallet, AddressGenerator
|
|
162
|
-
|
|
163
|
-
# Create wallet from mnemonic
|
|
164
|
-
mnemonic_phrase = "your twelve word mnemonic phrase goes here example test words"
|
|
165
|
-
wallet = HDWallet.from_mnemonic(mnemonic_phrase)
|
|
166
|
-
|
|
167
|
-
# Generate first 5 Bitcoin addresses
|
|
168
|
-
for i in range(5):
|
|
169
|
-
key = wallet.derive_address_key(coin_type=0, address_index=i)
|
|
170
|
-
|
|
171
|
-
# Generate different Bitcoin address formats
|
|
172
|
-
p2pkh = AddressGenerator.from_public_key(key.public_key, 'p2pkh', 'bitcoin')
|
|
173
|
-
p2wpkh = AddressGenerator.from_public_key(key.public_key, 'p2wpkh', 'bitcoin')
|
|
174
|
-
|
|
175
|
-
print(f"Address {i}:")
|
|
176
|
-
print(f" P2PKH: {p2pkh}")
|
|
177
|
-
print(f" P2WPKH: {p2wpkh}")
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
### Multi-Currency Wallet
|
|
181
|
-
|
|
182
|
-
```python
|
|
183
|
-
from wallet import HDWallet, AddressGenerator
|
|
184
|
-
from Util.constants import BIP44_COIN_TYPES
|
|
185
|
-
|
|
186
|
-
# Create wallet
|
|
187
|
-
wallet = HDWallet.from_mnemonic("your mnemonic here")
|
|
188
|
-
|
|
189
|
-
# Generate addresses for different cryptocurrencies
|
|
190
|
-
currencies = ['bitcoin', 'ethereum', 'litecoin', 'dogecoin']
|
|
191
|
-
|
|
192
|
-
for currency in currencies:
|
|
193
|
-
coin_type = BIP44_COIN_TYPES[currency]
|
|
194
|
-
key = wallet.derive_address_key(coin_type=coin_type, address_index=0)
|
|
195
|
-
|
|
196
|
-
if currency == 'ethereum':
|
|
197
|
-
address = AddressGenerator.from_public_key(key.public_key, 'ethereum', 'ethereum')
|
|
198
|
-
else:
|
|
199
|
-
address = AddressGenerator.from_public_key(key.public_key, 'p2pkh', currency)
|
|
200
|
-
|
|
201
|
-
print(f"{currency.capitalize()}: {address}")
|
|
202
|
-
```
|
|
203
|
-
|
|
204
|
-
## API Overview
|
|
205
|
-
|
|
206
|
-
### Mnemonic Module (`mnemonic.py`)
|
|
207
|
-
- `generate_mnemonic(word_count)` - Generate new mnemonic
|
|
208
|
-
- `validate_mnemonic(mnemonic)` - Validate existing mnemonic
|
|
209
|
-
- `mnemonic_to_seed(mnemonic, passphrase)` - Convert to seed
|
|
210
|
-
|
|
211
|
-
### HD Wallet (`wallet.HDWallet`)
|
|
212
|
-
- `from_mnemonic(mnemonic, passphrase, network)` - Create from mnemonic
|
|
213
|
-
- `derive_account(coin_type, account)` - Derive account key
|
|
214
|
-
- `derive_address_key(coin_type, account, change, address_index)` - Derive address key
|
|
215
|
-
|
|
216
|
-
### Private Key (`wallet.PrivateKey`)
|
|
217
|
-
- `generate(network)` - Generate new key
|
|
218
|
-
- `from_hex(hex_str, network)` - Import from hex
|
|
219
|
-
- `from_wif(wif)` - Import from WIF
|
|
220
|
-
- `to_wif(compressed)` - Export to WIF
|
|
221
|
-
- `get_public_key(compressed)` - Get public key
|
|
222
|
-
|
|
223
|
-
### Public Key (`wallet.PublicKey`)
|
|
224
|
-
- `from_hex(hex_str, compressed)` - Import from hex
|
|
225
|
-
- `get_address(address_type, network)` - Generate address
|
|
226
|
-
- `to_compressed()` / `to_uncompressed()` - Format conversion
|
|
227
|
-
|
|
228
|
-
### Address Generator (`wallet.AddressGenerator`)
|
|
229
|
-
- `from_public_key(public_key, address_type, network)` - Generate address
|
|
230
|
-
- `generate_multiple_formats(public_key, network)` - All formats
|
|
231
|
-
- `validate_address(address, network)` - Validate address
|
|
232
|
-
|
|
233
|
-
## Security Features
|
|
234
|
-
|
|
235
|
-
- **Cryptographically Secure**: Uses `secrets` module for random number generation
|
|
236
|
-
- **Proper Entropy**: Validates entropy for mnemonic generation
|
|
237
|
-
- **Checksum Validation**: All mnemonics include BIP39 checksum verification
|
|
238
|
-
- **Constant-Time Operations**: Where possible, uses constant-time implementations
|
|
239
|
-
- **Zero External Dependencies**: Reduces attack surface by avoiding third-party libraries
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
## Advanced Usage
|
|
244
|
-
|
|
245
|
-
### Custom Derivation Paths
|
|
246
|
-
|
|
247
|
-
```python
|
|
248
|
-
from wallet import HDWallet
|
|
249
|
-
|
|
250
|
-
wallet = HDWallet.from_mnemonic("your mnemonic")
|
|
251
|
-
|
|
252
|
-
# Custom derivation path
|
|
253
|
-
custom_path = "m/44'/0'/0'/0/5" # 6th address
|
|
254
|
-
custom_key = wallet.master_node.derive_path(custom_path)
|
|
255
|
-
|
|
256
|
-
# Account-level derivation for exchange integration
|
|
257
|
-
account_key = wallet.derive_account(coin_type=0, account=1) # Second account
|
|
258
|
-
```
|
|
259
|
-
|
|
260
|
-
### Batch Address Generation
|
|
261
|
-
|
|
262
|
-
```python
|
|
263
|
-
from wallet import HDWallet, AddressGenerator
|
|
264
|
-
|
|
265
|
-
def generate_address_batch(mnemonic, coin_type, count=100):
|
|
266
|
-
"""Generate a batch of addresses efficiently."""
|
|
267
|
-
wallet = HDWallet.from_mnemonic(mnemonic)
|
|
268
|
-
addresses = []
|
|
269
|
-
|
|
270
|
-
for i in range(count):
|
|
271
|
-
key = wallet.derive_address_key(coin_type=coin_type, address_index=i)
|
|
272
|
-
address = AddressGenerator.from_public_key(key.public_key, 'p2pkh', 'bitcoin')
|
|
273
|
-
addresses.append({
|
|
274
|
-
'index': i,
|
|
275
|
-
'address': address,
|
|
276
|
-
'private_key': key.private_key.hex(),
|
|
277
|
-
'public_key': key.public_key.hex()
|
|
278
|
-
})
|
|
279
|
-
|
|
280
|
-
return addresses
|
|
281
|
-
|
|
282
|
-
# Generate first 100 Bitcoin addresses
|
|
283
|
-
btc_addresses = generate_address_batch("your mnemonic", coin_type=0, count=100)
|
|
284
|
-
```
|
|
285
|
-
|
|
286
|
-
## Performance
|
|
287
|
-
|
|
288
|
-
Typical performance on modern hardware:
|
|
289
|
-
- **Mnemonic generation**: < 100ms
|
|
290
|
-
- **Address generation**: < 50ms per address
|
|
291
|
-
- **Key derivation**: < 200ms for complex paths
|
|
292
|
-
- **Memory usage**: < 50MB for typical operations
|
|
293
|
-
|
|
294
|
-
## Contributing
|
|
295
|
-
|
|
296
|
-
1. Fork the repository
|
|
297
|
-
2. Create a feature branch
|
|
298
|
-
3. Make your changes
|
|
299
|
-
4. Add tests for new functionality
|
|
300
|
-
5. Submit a pull request
|
|
301
|
-
|
|
302
|
-
## License
|
|
303
|
-
|
|
304
|
-
This project is licensed under the MIT License - see the LICENSE file for details.
|
|
305
|
-
|
|
306
|
-
## Standards Compliance
|
|
307
|
-
|
|
308
|
-
- **BIP-39**: Mnemonic code for generating deterministic keys
|
|
309
|
-
- **BIP-32**: Hierarchical Deterministic (HD) Wallets
|
|
310
|
-
- **BIP-44**: Multi-Account Hierarchy for Deterministic Wallets
|
|
311
|
-
- **EIP-55**: Mixed-case checksum address encoding (Ethereum)
|
|
312
|
-
- **RFC-6979**: Deterministic Usage of DSA and ECDSA
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
---
|
|
316
|
-
|
|
317
|
-
**LibCrypto** - Professional Cryptocurrency Wallet Library with Zero Dependencies
|
|
318
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|