LibCrypto
A professional library for Cryptography and Cryptocurrencies in Python.
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.
It has been a while since I published this new library to help and use other programmers who no longer have to get involved in various projects that need such tools, writing long source codes and using different libraries, which ultimately reduces the quality of the project.
In this library, an attempt has been made to make the most widely used and complex process for various cases into the shortest and most optimized standard form that can be used by the user, which has finally become, along with hundreds of different features of this library, the CryptoLib, which you can easily install and use in your source code or in the terminal (CLI).
Key Features
-
High-Level Wallet API: A simple
Walletclass to manage keys and addresses. -
Multi-Currency Support: Correctly generate addresses for numerous secp256k1-based cryptocurrencies, including:
- Bitcoin (BTC) - Legacy, SegWit (P2SH & Native)
- Ethereum (ETH)
- Tron (TRX)
- Ripple (XRP)
- Bitcoin Cash (BCH) - CashAddr format
- Litecoin (LTC)
- Dash (DASH)
- Dogecoin (DOGE)
- Hierarchical Deterministic (HD) Wallets: Full BIP32 support for generating wallets from a master seed.
- BIP39 Mnemonic Support: Generate, validate, and derive seeds from mnemonic phrases.
- Key & Format Conversions: Easily convert between WIF, Hex, and Bytes for private and public keys.
- Powerful Command-Line Interface: Perform common wallet operations directly from your terminal.
Installation
Install the library using pip:
pip install libcrypto
Quick Start (Library Usage)
from libcrypto import Wallet
key = "Your Private Key (hex | bytes | int | Wif)"
# Initialize the Wallet with the private key
wallet = Wallet(key)
Generated Bitcoin Wallet Addresses from Private Key
# Generate P2PKH, P2SH-P2WPKH, P2WPKH addresses for Bitcoin
p2pkh = wallet.get_address(coin="bitcoin", address_type="p2pkh")
p2wsh = wallet.get_address(coin="bitcoin", address_type="p2sh-p2wpkh")
p2wpkh = wallet.get_address(coin="bitcoin", address_type="p2wpkh")
Generated Ethereum Wallet from Private Key
# Generate ethereum Address
ethereum_address = wallet.get_address(coin="ethereum")
Generated Tron Wallet from Private Key
# Generate Tron Address
tron_address = wallet.get_address(coin="tron")
Generated Ripple Wallet from Private Key (Hex)
# Generate Ripple Address
ripple_address = wallet.get_address(coin="ripple")
Generated Dash Wallet from Private Key
# Generate Dash Address
dash = wallet.get_address(coin="dash")
Generated Dogecoin Wallet from Private Key
# Generate Dogecoin Address
dogecoin_address = wallet.get_address(coin="dogecoin")
Generated Litecoin Addresses From Private Key
# Generate Litecoin Address
litecoin_address = wallet.get_address(coin="litecoin")
# Generate Litecoin Address with specific address types
litecoin_address_p2pkh = wallet.get_address(coin="litecoin", address_type="p2pkh")
litecoin_address_p2wsh = wallet.get_address(coin="litecoin", address_type="p2sh-p2wpkh")
litecoin_address_p2wpkh = wallet.get_address(coin="litecoin", address_type="p2wpkh")
The library is designed to be straightforward. Here is a basic example of generating addresses from an existing private key.
from libcrypto import Wallet
# Initialize a wallet from a WIF private key
wif_key = "L4ZQks37JHUadEqaj2nGB1eaZFcsRZwZGQ7WVYuQiztzg4pqopU6" # Example
wallet = Wallet(wif_key)
# Generate addresses for different coins
eth_address = wallet.get_address('ethereum')
btc_address = wallet.get_address('bitcoin', address_type='p2wpkh') # Native SegWit
bch_address = wallet.get_address('bitcoin_cash')
print(f"Ethereum Address: {eth_address}")
print(f"Bitcoin (SegWit) Address: {btc_address}")
print(f"Bitcoin Cash Address: {bch_address}")
Generated Bitcoin Compressed and Uncompressed Address Wallet
from libcrypto import PrivateKey
# Key generation
key = PrivateKey(network="bitcoin")
# Generate Public Key (compressed and uncompressed)
public_compressed = key.get_public_key(compressed=True)
public_uncompressed = key.get_public_key(compressed=False)
# Compressed and Uncompressed Addresses
address_compressed = public_compressed.get_address()
address_uncompressed = public_uncompressed.get_address()
Generated Wif Compressed and Uncompressed
from libcrypto import PrivateKey
# Key generation
key = PrivateKey(network="bitcoin")
# Wif compressed and Uncompressed
wif_compressed = key.to_wif(compressed=True)
wif_uncompressed = key.to_wif(compressed=False)
Quick Start (Command-Line Interface)
# version
libcrypto -v
Package Information:
libcrypto info
Wallet & Address Generation
- Generate a Wallet: This is the main command for generating new wallets or deriving addresses from existing keys.
libcrypto generate [OPTIONS]
Options:
-
-p,--private-keyTEXT: Derive addresses from an existing private key (WIF or Hex format). If omitted, a new random wallet is generated. -
-c,--coinTEXT: Specify a coin to generate addresses for. This option can be used multiple times. Defaults to bitcoin and ethereum.
- Generate a new wallet for Bitcoin and Litecoin:
libcrypto generate -c bitcoin -c litecoin
- Generate a wallet from an existing private key:
libcrypto generate -p <your-private-key>
- Derive addresses for a specific set of coins from a hex key:
libcrypto generate -p <your-hex-key> -c bitcoin -c ethereum -c dash -c tron
Mnemonic Management
The mnemonic subcommand is used for all BIP39 mnemonic phrase operations.
Generate a Mnemonic Phrase
Creates a new, cryptographically secure BIP39 mnemonic phrase.
libcrypto mnemonic generate [OPTIONS]
Options:
-
-w,--wordsINTEGER: The number of words in the mnemonic. Can be 12, 15, 18, 21, or 24. [Default: 12]
Example:
libcrypto mnemonic generate --words 24
Validate a Mnemonic Phrase
Checks if a given BIP39 mnemonic phrase is valid according to the checksum rules.
libcrypto mnemonic validate "PHRASE"
Arguments:
-
PHRASE: The full mnemonic phrase, enclosed in double quotes. [Required]
Example:
libcrypto mnemonic validate "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"

Top comments (0)