libcrypto 1.0.1__tar.gz
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-1.0.1/LICENSE +21 -0
- libcrypto-1.0.1/PKG-INFO +318 -0
- libcrypto-1.0.1/README.md +285 -0
- libcrypto-1.0.1/pyproject.toml +60 -0
- libcrypto-1.0.1/setup.cfg +4 -0
- libcrypto-1.0.1/setup.py +87 -0
- libcrypto-1.0.1/src/libcrypto/__init__.py +72 -0
- libcrypto-1.0.1/src/libcrypto/_version.py +19 -0
- libcrypto-1.0.1/src/libcrypto/addresses.py +191 -0
- libcrypto-1.0.1/src/libcrypto/bip32.py +234 -0
- libcrypto-1.0.1/src/libcrypto/cli.py +159 -0
- libcrypto-1.0.1/src/libcrypto/constants.py +288 -0
- libcrypto-1.0.1/src/libcrypto/formats.py +164 -0
- libcrypto-1.0.1/src/libcrypto/hash.py +88 -0
- libcrypto-1.0.1/src/libcrypto/keys.py +149 -0
- libcrypto-1.0.1/src/libcrypto/mnemonic.py +156 -0
- libcrypto-1.0.1/src/libcrypto/secp256k1.py +117 -0
- libcrypto-1.0.1/src/libcrypto/wallet.py +135 -0
- libcrypto-1.0.1/src/libcrypto.egg-info/PKG-INFO +318 -0
- libcrypto-1.0.1/src/libcrypto.egg-info/SOURCES.txt +23 -0
- libcrypto-1.0.1/src/libcrypto.egg-info/dependency_links.txt +1 -0
- libcrypto-1.0.1/src/libcrypto.egg-info/entry_points.txt +2 -0
- libcrypto-1.0.1/src/libcrypto.egg-info/not-zip-safe +1 -0
- libcrypto-1.0.1/src/libcrypto.egg-info/requires.txt +4 -0
- libcrypto-1.0.1/src/libcrypto.egg-info/top_level.txt +1 -0
libcrypto-1.0.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 LibCrypto Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
libcrypto-1.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,318 @@
|
|
|
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
|
+
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
# LibCrypto - Cryptocurrency Wallet Library
|
|
2
|
+
|
|
3
|
+
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**.
|
|
4
|
+
|
|
5
|
+
## 🚀 Features
|
|
6
|
+
|
|
7
|
+
### Core Functionality
|
|
8
|
+
- **BIP39 Mnemonic Phrases**: Generate and validate secure mnemonic phrases (12, 15, 18, 21, 24 words)
|
|
9
|
+
- **BIP32 HD Wallets**: Hierarchical deterministic wallet support with full BIP44 compliance
|
|
10
|
+
- **Multi-Currency Support**: Generate addresses for 13+ cryptocurrencies
|
|
11
|
+
- **Key Format Conversions**: Convert between hex, WIF, bytes, decimal, and mnemonic formats
|
|
12
|
+
- **Zero Dependencies**: Uses only Python standard library and included C extensions
|
|
13
|
+
|
|
14
|
+
### Supported Cryptocurrencies
|
|
15
|
+
- **Bitcoin (BTC)** - P2PKH, P2SH, P2WPKH, P2WSH (SegWit)
|
|
16
|
+
- **Ethereum (ETH)** - Native addresses with EIP-55 checksum
|
|
17
|
+
- **Litecoin (LTC)** - All Bitcoin-compatible formats
|
|
18
|
+
- **Bitcoin Cash (BCH)** - Legacy and CashAddr formats
|
|
19
|
+
- **Bitcoin Gold (BTG)** - All standard formats
|
|
20
|
+
- **Dogecoin (DOGE)** - P2PKH and P2SH
|
|
21
|
+
- **Dash** - P2PKH and P2SH
|
|
22
|
+
- **Digibyte (DGB)** - All standard formats
|
|
23
|
+
- **Zcash (ZEC)** - T-addresses
|
|
24
|
+
- **Tron (TRX)** - Native TRX addresses
|
|
25
|
+
- **Solana (SOL)** - Base58 encoded addresses
|
|
26
|
+
- **Avalanche (AVAX)** - C-Chain addresses
|
|
27
|
+
- **TON** - Native TON addresses
|
|
28
|
+
- **Ripple (XRP)** - Classic addresses
|
|
29
|
+
|
|
30
|
+
### Address Formats
|
|
31
|
+
- **P2PKH**: Pay to Public Key Hash (1...)
|
|
32
|
+
- **P2SH**: Pay to Script Hash (3...)
|
|
33
|
+
- **P2WPKH**: Pay to Witness Public Key Hash (bc1...)
|
|
34
|
+
- **P2WSH**: Pay to Witness Script Hash (bc1...)
|
|
35
|
+
- **Ethereum**: Keccak256-based addresses (0x...)
|
|
36
|
+
|
|
37
|
+
## 📦 Installation
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
# Clone the repository
|
|
41
|
+
git clone <repository-url>
|
|
42
|
+
cd libcrypto
|
|
43
|
+
|
|
44
|
+
# Install in development mode
|
|
45
|
+
pip install -e .
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## 🔧 Quick Start
|
|
49
|
+
|
|
50
|
+
### Generate a New Mnemonic and Wallet
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
import mnemonic
|
|
54
|
+
from wallet import HDWallet, PrivateKey, AddressGenerator
|
|
55
|
+
|
|
56
|
+
# Generate a new 12-word mnemonic
|
|
57
|
+
new_mnemonic = mnemonic.generate_mnemonic(12)
|
|
58
|
+
print(f"Generated mnemonic: {new_mnemonic}")
|
|
59
|
+
|
|
60
|
+
# Create HD wallet from mnemonic
|
|
61
|
+
wallet = HDWallet.from_mnemonic(new_mnemonic)
|
|
62
|
+
|
|
63
|
+
# Get Bitcoin address (BIP44 path: m/44'/0'/0'/0/0)
|
|
64
|
+
btc_key = wallet.derive_address_key(coin_type=0, address_index=0)
|
|
65
|
+
btc_address = AddressGenerator.from_public_key(
|
|
66
|
+
btc_key.public_key, 'p2pkh', 'bitcoin'
|
|
67
|
+
)
|
|
68
|
+
print(f"Bitcoin address: {btc_address}")
|
|
69
|
+
|
|
70
|
+
# Get Ethereum address (BIP44 path: m/44'/60'/0'/0/0)
|
|
71
|
+
eth_key = wallet.derive_address_key(coin_type=60, address_index=0)
|
|
72
|
+
eth_address = AddressGenerator.from_public_key(
|
|
73
|
+
eth_key.public_key, 'ethereum', 'ethereum'
|
|
74
|
+
)
|
|
75
|
+
print(f"Ethereum address: {eth_address}")
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Import Existing Mnemonic
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
import mnemonic
|
|
82
|
+
from wallet import HDWallet
|
|
83
|
+
|
|
84
|
+
# Import existing mnemonic
|
|
85
|
+
existing_mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
|
|
86
|
+
|
|
87
|
+
# Validate mnemonic
|
|
88
|
+
if mnemonic.validate_mnemonic(existing_mnemonic):
|
|
89
|
+
print("✅ Mnemonic is valid")
|
|
90
|
+
|
|
91
|
+
# Create wallet
|
|
92
|
+
wallet = HDWallet.from_mnemonic(existing_mnemonic)
|
|
93
|
+
|
|
94
|
+
# Get master keys
|
|
95
|
+
print(f"Master private key: {wallet.get_master_private_key()}")
|
|
96
|
+
print(f"Master public key: {wallet.get_master_public_key()}")
|
|
97
|
+
else:
|
|
98
|
+
print("❌ Invalid mnemonic")
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Private Key Operations
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
from wallet import PrivateKey
|
|
105
|
+
|
|
106
|
+
# Generate a new private key
|
|
107
|
+
private_key = PrivateKey.generate()
|
|
108
|
+
|
|
109
|
+
# Convert to different formats
|
|
110
|
+
print(f"Hex: {private_key.hex}")
|
|
111
|
+
print(f"WIF: {private_key.to_wif()}")
|
|
112
|
+
print(f"Decimal: {private_key.decimal}")
|
|
113
|
+
|
|
114
|
+
# Get public key and address
|
|
115
|
+
public_key = private_key.get_public_key()
|
|
116
|
+
btc_address = public_key.get_address('p2pkh', 'bitcoin')
|
|
117
|
+
print(f"Bitcoin address: {btc_address}")
|
|
118
|
+
|
|
119
|
+
# Import from hex
|
|
120
|
+
hex_key = "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"
|
|
121
|
+
imported_key = PrivateKey.from_hex(hex_key)
|
|
122
|
+
print(f"Imported key WIF: {imported_key.to_wif()}")
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Multiple Address Generation
|
|
126
|
+
|
|
127
|
+
```python
|
|
128
|
+
from wallet import HDWallet, AddressGenerator
|
|
129
|
+
|
|
130
|
+
# Create wallet from mnemonic
|
|
131
|
+
mnemonic_phrase = "your twelve word mnemonic phrase goes here example test words"
|
|
132
|
+
wallet = HDWallet.from_mnemonic(mnemonic_phrase)
|
|
133
|
+
|
|
134
|
+
# Generate first 5 Bitcoin addresses
|
|
135
|
+
for i in range(5):
|
|
136
|
+
key = wallet.derive_address_key(coin_type=0, address_index=i)
|
|
137
|
+
|
|
138
|
+
# Generate different Bitcoin address formats
|
|
139
|
+
p2pkh = AddressGenerator.from_public_key(key.public_key, 'p2pkh', 'bitcoin')
|
|
140
|
+
p2wpkh = AddressGenerator.from_public_key(key.public_key, 'p2wpkh', 'bitcoin')
|
|
141
|
+
|
|
142
|
+
print(f"Address {i}:")
|
|
143
|
+
print(f" P2PKH: {p2pkh}")
|
|
144
|
+
print(f" P2WPKH: {p2wpkh}")
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Multi-Currency Wallet
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
from wallet import HDWallet, AddressGenerator
|
|
151
|
+
from Util.constants import BIP44_COIN_TYPES
|
|
152
|
+
|
|
153
|
+
# Create wallet
|
|
154
|
+
wallet = HDWallet.from_mnemonic("your mnemonic here")
|
|
155
|
+
|
|
156
|
+
# Generate addresses for different cryptocurrencies
|
|
157
|
+
currencies = ['bitcoin', 'ethereum', 'litecoin', 'dogecoin']
|
|
158
|
+
|
|
159
|
+
for currency in currencies:
|
|
160
|
+
coin_type = BIP44_COIN_TYPES[currency]
|
|
161
|
+
key = wallet.derive_address_key(coin_type=coin_type, address_index=0)
|
|
162
|
+
|
|
163
|
+
if currency == 'ethereum':
|
|
164
|
+
address = AddressGenerator.from_public_key(key.public_key, 'ethereum', 'ethereum')
|
|
165
|
+
else:
|
|
166
|
+
address = AddressGenerator.from_public_key(key.public_key, 'p2pkh', currency)
|
|
167
|
+
|
|
168
|
+
print(f"{currency.capitalize()}: {address}")
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## API Overview
|
|
172
|
+
|
|
173
|
+
### Mnemonic Module (`mnemonic.py`)
|
|
174
|
+
- `generate_mnemonic(word_count)` - Generate new mnemonic
|
|
175
|
+
- `validate_mnemonic(mnemonic)` - Validate existing mnemonic
|
|
176
|
+
- `mnemonic_to_seed(mnemonic, passphrase)` - Convert to seed
|
|
177
|
+
|
|
178
|
+
### HD Wallet (`wallet.HDWallet`)
|
|
179
|
+
- `from_mnemonic(mnemonic, passphrase, network)` - Create from mnemonic
|
|
180
|
+
- `derive_account(coin_type, account)` - Derive account key
|
|
181
|
+
- `derive_address_key(coin_type, account, change, address_index)` - Derive address key
|
|
182
|
+
|
|
183
|
+
### Private Key (`wallet.PrivateKey`)
|
|
184
|
+
- `generate(network)` - Generate new key
|
|
185
|
+
- `from_hex(hex_str, network)` - Import from hex
|
|
186
|
+
- `from_wif(wif)` - Import from WIF
|
|
187
|
+
- `to_wif(compressed)` - Export to WIF
|
|
188
|
+
- `get_public_key(compressed)` - Get public key
|
|
189
|
+
|
|
190
|
+
### Public Key (`wallet.PublicKey`)
|
|
191
|
+
- `from_hex(hex_str, compressed)` - Import from hex
|
|
192
|
+
- `get_address(address_type, network)` - Generate address
|
|
193
|
+
- `to_compressed()` / `to_uncompressed()` - Format conversion
|
|
194
|
+
|
|
195
|
+
### Address Generator (`wallet.AddressGenerator`)
|
|
196
|
+
- `from_public_key(public_key, address_type, network)` - Generate address
|
|
197
|
+
- `generate_multiple_formats(public_key, network)` - All formats
|
|
198
|
+
- `validate_address(address, network)` - Validate address
|
|
199
|
+
|
|
200
|
+
## Security Features
|
|
201
|
+
|
|
202
|
+
- **Cryptographically Secure**: Uses `secrets` module for random number generation
|
|
203
|
+
- **Proper Entropy**: Validates entropy for mnemonic generation
|
|
204
|
+
- **Checksum Validation**: All mnemonics include BIP39 checksum verification
|
|
205
|
+
- **Constant-Time Operations**: Where possible, uses constant-time implementations
|
|
206
|
+
- **Zero External Dependencies**: Reduces attack surface by avoiding third-party libraries
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
## Advanced Usage
|
|
211
|
+
|
|
212
|
+
### Custom Derivation Paths
|
|
213
|
+
|
|
214
|
+
```python
|
|
215
|
+
from wallet import HDWallet
|
|
216
|
+
|
|
217
|
+
wallet = HDWallet.from_mnemonic("your mnemonic")
|
|
218
|
+
|
|
219
|
+
# Custom derivation path
|
|
220
|
+
custom_path = "m/44'/0'/0'/0/5" # 6th address
|
|
221
|
+
custom_key = wallet.master_node.derive_path(custom_path)
|
|
222
|
+
|
|
223
|
+
# Account-level derivation for exchange integration
|
|
224
|
+
account_key = wallet.derive_account(coin_type=0, account=1) # Second account
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### Batch Address Generation
|
|
228
|
+
|
|
229
|
+
```python
|
|
230
|
+
from wallet import HDWallet, AddressGenerator
|
|
231
|
+
|
|
232
|
+
def generate_address_batch(mnemonic, coin_type, count=100):
|
|
233
|
+
"""Generate a batch of addresses efficiently."""
|
|
234
|
+
wallet = HDWallet.from_mnemonic(mnemonic)
|
|
235
|
+
addresses = []
|
|
236
|
+
|
|
237
|
+
for i in range(count):
|
|
238
|
+
key = wallet.derive_address_key(coin_type=coin_type, address_index=i)
|
|
239
|
+
address = AddressGenerator.from_public_key(key.public_key, 'p2pkh', 'bitcoin')
|
|
240
|
+
addresses.append({
|
|
241
|
+
'index': i,
|
|
242
|
+
'address': address,
|
|
243
|
+
'private_key': key.private_key.hex(),
|
|
244
|
+
'public_key': key.public_key.hex()
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
return addresses
|
|
248
|
+
|
|
249
|
+
# Generate first 100 Bitcoin addresses
|
|
250
|
+
btc_addresses = generate_address_batch("your mnemonic", coin_type=0, count=100)
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
## Performance
|
|
254
|
+
|
|
255
|
+
Typical performance on modern hardware:
|
|
256
|
+
- **Mnemonic generation**: < 100ms
|
|
257
|
+
- **Address generation**: < 50ms per address
|
|
258
|
+
- **Key derivation**: < 200ms for complex paths
|
|
259
|
+
- **Memory usage**: < 50MB for typical operations
|
|
260
|
+
|
|
261
|
+
## Contributing
|
|
262
|
+
|
|
263
|
+
1. Fork the repository
|
|
264
|
+
2. Create a feature branch
|
|
265
|
+
3. Make your changes
|
|
266
|
+
4. Add tests for new functionality
|
|
267
|
+
5. Submit a pull request
|
|
268
|
+
|
|
269
|
+
## License
|
|
270
|
+
|
|
271
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
|
272
|
+
|
|
273
|
+
## Standards Compliance
|
|
274
|
+
|
|
275
|
+
- **BIP-39**: Mnemonic code for generating deterministic keys
|
|
276
|
+
- **BIP-32**: Hierarchical Deterministic (HD) Wallets
|
|
277
|
+
- **BIP-44**: Multi-Account Hierarchy for Deterministic Wallets
|
|
278
|
+
- **EIP-55**: Mixed-case checksum address encoding (Ethereum)
|
|
279
|
+
- **RFC-6979**: Deterministic Usage of DSA and ECDSA
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
---
|
|
283
|
+
|
|
284
|
+
**LibCrypto** - Professional Cryptocurrency Wallet Library with Zero Dependencies
|
|
285
|
+
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# pyproject.toml
|
|
2
|
+
|
|
3
|
+
[build-system]
|
|
4
|
+
# This section defines the build system requirements for the package.
|
|
5
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
6
|
+
build-backend = "setuptools.build_meta"
|
|
7
|
+
|
|
8
|
+
[project]
|
|
9
|
+
# Metadatas for the package.
|
|
10
|
+
name = "libcrypto"
|
|
11
|
+
authors = [
|
|
12
|
+
{ name = "Mmdrza", email = "pymmdrza@gmail.com" },
|
|
13
|
+
]
|
|
14
|
+
description = "A professional library For Cryptography and Cryptocurrencies in Python."
|
|
15
|
+
readme = "README.md"
|
|
16
|
+
requires-python = ">=3.8"
|
|
17
|
+
license = { text = "MIT" }
|
|
18
|
+
classifiers = [
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.8",
|
|
21
|
+
"Programming Language :: Python :: 3.9",
|
|
22
|
+
"Programming Language :: Python :: 3.10",
|
|
23
|
+
"Programming Language :: Python :: 3.11",
|
|
24
|
+
"License :: OSI Approved :: MIT License",
|
|
25
|
+
"Operating System :: OS Independent",
|
|
26
|
+
"Intended Audience :: Developers",
|
|
27
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
28
|
+
"Topic :: Security :: Cryptography",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
# Dependencies required for the package.
|
|
32
|
+
dependencies = [
|
|
33
|
+
"pycryptodome",
|
|
34
|
+
"ecdsa",
|
|
35
|
+
"rich",
|
|
36
|
+
"typer",
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
# Optional dependencies that can be installed with the package.
|
|
40
|
+
dynamic = ["version"]
|
|
41
|
+
|
|
42
|
+
[project.urls]
|
|
43
|
+
Homepage = "https://libcrypto.readthedocs.io/"
|
|
44
|
+
Repository = "https://github.com/Pymmdrza/libcrypto"
|
|
45
|
+
"Bug Tracker" = "https://github.com/Pymmdrza/libcrypto/issues"
|
|
46
|
+
|
|
47
|
+
[project.scripts]
|
|
48
|
+
libcrypto = "libcrypto.cli:app"
|
|
49
|
+
|
|
50
|
+
[tool.setuptools]
|
|
51
|
+
# Package file structure.
|
|
52
|
+
package-dir = { "" = "src" }
|
|
53
|
+
|
|
54
|
+
[tool.setuptools.packages.find]
|
|
55
|
+
# Library packages to include in the distribution.
|
|
56
|
+
where = ["src"]
|
|
57
|
+
|
|
58
|
+
[tool.setuptools.dynamic]
|
|
59
|
+
# Read the version dynamically from the __init__.py file.
|
|
60
|
+
version = { attr = "libcrypto.__version__" }
|