This document demonstrates how to use Python and the mnemonic library to generate a seed phrase and derive a private key. The name of this repository, "How to Kill Crypto Money/Wallet," is intentionally ironic. While the techniques described herein can indeed be used to manipulate and even destroy wallets/crypto assets, the primary purpose of this repository is to educate and practice security measures. It's important to note that although these tools can be repurposed by malicious actors, this repository is intended strictly for educational and security testing purposes. I explicitly distance ourselves from any misuse of the knowledge and tools provided here.
Warning
This codes are intended for demonstration purposes only and should never be used with real funds or your actual hardware wallet.
- Introduction
- Security Risks and Vulnerabilities
- Generating a Seed Phrase
- Deriving a Private Key
- Generating Addresses from Seed Phrases
- Signing Transactions
- Reading and Validating Seed Phrases
- Using Hardware Wallets
- Detecting and Preventing Seed Phrase Leaks
- Important Warnings
- Examples
- Your Support
Working with mnemonic libraries and private keys involves significant security risks. Improper handling of seed phrases and private keys can lead to the loss of funds. Always ensure you are following best practices for security:
- Store your seed phrase in a secure location.
- Never share your private key with anyone.
- Use secure, isolated environments when working with sensitive information.
The following Python code generates a seed phrase using the mnemonic library. This seed phrase can be used to derive a private key.
import mnemonic
# Generate a seed phrase (using the default English word list)
seed = mnemonic.Mnemonic('english').generate(strength=128)
print("Seed Phrase:", seed)
This code generates a random seed phrase with 128 bits of entropy, consisting of 12 words from the English word list.
The seed phrase can be converted into a private key, which can be used for signing transactions.
import binascii
# Convert the seed phrase into a private key
private_key = binascii.hexlify(mnemonic.Mnemonic('english').to_seed(seed)).decode()
print("Private Key:", private_key)
This code converts the seed phrase into a private key. The binascii.hexlify()
function transforms the byte sequence of the private key into a hexadecimal string.
You can derive public addresses from a seed phrase, which are used in blockchain transactions.
from mnemonic import Mnemonic
import bip32utils
# Generate a seed phrase
mnemo = Mnemonic('english')
seed = mnemo.generate(strength=128)
print("Seed Phrase:", seed)
# Convert the seed phrase to a seed
seed_bytes = mnemo.to_seed(seed)
# Create a BIP32 root key from the seed
root_key = bip32utils.BIP32Key.fromEntropy(seed_bytes)
# Generate a Bitcoin address
address = root_key.Address()
print("Bitcoin Address:", address)
This code generates a Bitcoin address from a seed phrase using BIP32.
The private key can be used to sign transactions. Note that this is just a demonstration and should not be used with real funds.
import mnemonic
import binascii
import hashlib
import hmac
# Generate a seed phrase
seed = mnemonic.Mnemonic('english').generate(strength=128)
print("Seed Phrase:", seed)
# Convert the seed phrase into a private key
private_key = binascii.hexlify(mnemonic.Mnemonic('english').to_seed(seed)).decode()
print("Private Key:", private_key)
# Example function to sign a transaction
def sign_transaction(transaction, private_key):
# Convert the private key from hex to bytes
private_key_bytes = binascii.unhexlify(private_key)
# Create a HMAC object using the private key and SHA256
h = hmac.new(private_key_bytes, transaction.encode('utf-8'), hashlib.sha256)
# Generate the signature
signature = h.hexdigest()
return signature
# Hypothetical transaction data
transaction_data = "example_transaction_data"
# Sign the transaction
signed_transaction = sign_transaction(transaction_data, private_key)
print("Signed Transaction:", signed_transaction)
You can also read an existing seed phrase and validate it using the mnemonic library.
# Read and validate a seed phrase
seed_phrase = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
# Check if the seed phrase is valid
is_valid = mnemonic.Mnemonic('english').check(seed_phrase)
print("Is the seed phrase valid?", is_valid)
# Convert the valid seed phrase into a private key
if is_valid:
private_key = binascii.hexlify(mnemonic.Mnemonic('english').to_seed(seed_phrase)).decode()
print("Private Key:", private_key)
else:
print("The seed phrase is invalid. Please provide a valid seed phrase.")
This example shows how to validate a given seed phrase and convert it into a private key if it is valid.
Integrating mnemonic libraries with hardware wallets adds an extra layer of security.
# This is a placeholder for actual hardware wallet integration code
# Example:
# from hardware_wallet_library import HardwareWallet
# wallet = HardwareWallet()
# wallet.load_seed(seed)
# address = wallet.get_address()
# print("Hardware Wallet Address:", address)
Scripts to detect common patterns of seed phrase leaks and how to prevent them.
# Example of a simple script to check for seed phrase leaks in a file
def check_for_seed_phrases(file_path):
with open(file_path, 'r') as file:
content = file.read()
if "abandon abandon abandon" in content:
print("Potential seed phrase leak detected!")
else:
print("No seed phrase leaks detected.")
# Check a sample file for leaks
check_for_seed_phrases('sample_file.txt')
- Secure Your Seed Phrase: Store your seed phrase in a secure location, as it is the only way to access your cryptocurrency.
- Do Not Use This Code with Real Funds: This code is for demonstration purposes only. Never use it with your actual private key or real funds, as you risk losing your money.
- Learn About Cryptography: It is crucial to understand the basics of cryptography and hardware wallet security before experimenting with real funds.
Here are some practical examples of using the mnemonic library:
import mnemonic
# Generate a seed phrase
seed = mnemonic.Mnemonic('english').generate(strength=128)
print("Seed Phrase:", seed)
import mnemonic
import binascii
# Generate a seed phrase
seed = mnemonic.Mnemonic('english').generate(strength=128)
# Convert the seed phrase into a private key
private_key = binascii.hexlify(mnemonic.Mnemonic('english').to_seed(seed)).decode()
print("Private Key:", private_key)
import mnemonic
import binascii
import hashlib
import hmac
# Generate a seed phrase
seed = mnemonic.Mnemonic('english').generate(strength=128)
# Convert the seed phrase into a private key
private_key = binascii.hexlify(mnemonic.Mnemonic('english').to_seed(seed)).decode()
# Example function to sign a transaction
def sign_transaction(transaction, private_key):
# Convert the private key from hex to bytes
private_key_bytes = binascii.unhexlify(private_key)
# Create a HMAC object using the private key and SHA256
h = hmac.new(private_key_bytes, transaction.encode('utf-8'), hashlib.sha256)
# Generate the signature
signature = h.hexdigest()
return signature
# Hypothetical transaction data
transaction_data = "example_transaction_data"
# Sign the transaction
signed_transaction = sign_transaction(transaction_data, private_key)
print("Signed Transaction:", signed_transaction)
import mnemonic
import binascii
# Read and validate a seed phrase
seed_phrase = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
# Check if the seed phrase is valid
is_valid = mnemonic.Mnemonic('english').check(seed_phrase)
print("Is the seed phrase valid?", is_valid)
# Convert the valid seed phrase into a private key
if is_valid:
private_key = binascii.hexlify(mnemonic.Mnemonic('english').to_seed(seed_phrase)).decode()
print("Private Key:", private_key)
else:
print("The seed phrase is invalid. Please provide a valid seed phrase.")
Issues for this script are not accepted as it is intended for educational purposes only and not for production use. However, you are welcome to make a Pull Request (PR) for contributions.
Warning
Exploiting security vulnerabilities without permission and manipulating or destroying cryptocurrency wallets is illegal and unethical, and may result in criminal charges.
If you find this project useful and want to support it, there are several ways to do so:
- If you find the white paper helpful, please ⭐ it on GitHub. This helps make the project more visible and reach more people.
- Become a Follower: If you're interested in updates and future improvements, please follow my GitHub account. This way you'll always stay up-to-date.
- Learn more about my work: I invite you to check out all of my work on GitHub and visit my developer site https://volkansah.github.io. Here you will find detailed information about me and my projects.
- Share the project: If you know someone who could benefit from this project, please share it. The more people who can use it, the better. If you appreciate my work and would like to support it, please visit my GitHub Sponsor page. Any type of support is warmly welcomed and helps me to further improve and expand my work.
Thank you for your support! ❤️