This section will show everyone how to generate wallets for different Crypto Currencies.
XRP ed Encryption
import hashlib
import binascii
from xrpl.core import keypairs
from xrpl.wallet import Wallet
def generate_wallet_from_hex_seed(hex_seed: str):
# Ensure the seed is a 64-character hexadecimal string
if len(hex_seed) != 64 or not all(c in '0123456789abcdefABCDEF' for c in hex_seed):
raise ValueError("Seed must be a 64-character hexadecimal string.")
# Truncate the hex seed to 32 characters (16 bytes)
truncated_hex_seed = hex_seed[:32]
# Generate the seed using the truncated hex seed
seed = keypairs.generate_seed(truncated_hex_seed)
# Create wallet from seed
wallet = Wallet.from_seed(seed)
# Derive classic address
classic_address = wallet.classic_address
# Derive public and private keys
public_key = wallet.public_key
private_key = wallet.private_key
# Derive X-address
x_address = wallet.get_xaddress()
return {
"seed": seed,
"classic_address": classic_address,
"public_key": public_key,
"private_key": private_key,
"x_address": x_address
}
# Example usage
if __name__ == "__main__":
# Replace this with your 64-character hexadecimal seed
hex_seed = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
wallet_info = generate_wallet_from_hex_seed(hex_seed)
for key, value in wallet_info.items():
print(f"{key}: {value}")
XRP SECP256K1 Encryption
import binascii
from ecdsa import SigningKey, SECP256k1
from xrpl.core import keypairs, addresscodec
def generate_xrp_wallet_from_hex(hex_private_key):
"""
Generates an XRP wallet (secp256k1) from a 64-character hex private key.
"""
# Ensure the private key is 64 characters long
if len(hex_private_key) != 64:
raise ValueError("The private key must be a 64-character hexadecimal string.")
# Convert hex private key to bytes
private_key_bytes = binascii.unhexlify(hex_private_key)
# Create a SigningKey object from the private key
signing_key = SigningKey.from_string(private_key_bytes, curve=SECP256k1)
# Obtain the verifying (public) key in compressed format
verifying_key = signing_key.get_verifying_key()
public_key_bytes = (
b'\x02' + verifying_key.to_string()[:32]
if verifying_key.pubkey.point.y() % 2 == 0
else b'\x03' + verifying_key.to_string()[:32]
)
public_key_hex = public_key_bytes.hex().upper()
# Derive the classic address from the public key
classic_address = keypairs.derive_classic_address(public_key_hex)
# Generate the X-address (tag is None for a regular wallet)
x_address = addresscodec.classic_address_to_xaddress(
classic_address, tag=None, is_test_network=False
)
return {
"Classic Address": classic_address,
"X-Address": x_address,
"Public Key": public_key_hex,
"Private Key": hex_private_key,
}
# Example usage:
hex_private_key = (
"F3A6B1C29D6D6D3CDBB6D8E48671A7F84993552B965299A3F529B5DE8AF7F8C3" # Replace with your 64-character hex
)
wallet_info = generate_xrp_wallet_from_hex(hex_private_key)
# Print results
for key, value in wallet_info.items():
print(f"{key}: {value}")
Solana
import binascii
from bip_utils import (
Bip39MnemonicGenerator, Bip39SeedGenerator,
Bip44, Bip44Coins, Bip44Changes
)
def generate_solana_wallet(hex_entropy: str):
"""
Generates a Solana wallet using a given 64-character hex string as entropy.
Returns a dict with:
- mnemonic: the BIP-39 mnemonic phrase.
- seed: the seed in hex.
- address: the Solana wallet address (base58 encoded public key).
- public_key: the public key in hex.
- private_key: the private key in hex.
Note: The derivation path is not returned because the latest bip_utils
does not provide a method to retrieve it automatically.
"""
if len(hex_entropy) != 64:
raise ValueError("Entropy must be a 64-character hex string representing 256 bits.")
# Convert hex string to bytes and generate mnemonic
entropy_bytes = bytes.fromhex(hex_entropy)
mnemonic = Bip39MnemonicGenerator().FromEntropy(entropy_bytes)
# Generate seed from mnemonic (empty passphrase by default)
seed_bytes = Bip39SeedGenerator(mnemonic).Generate()
# Derive Solana wallet using Bip44 (coin type 501 corresponds to Solana)
bip44_mst_ctx = Bip44.FromSeed(seed_bytes, Bip44Coins.SOLANA)
bip44_acc_ctx = bip44_mst_ctx.Purpose().Coin().Account(0).Change(Bip44Changes.CHAIN_EXT).AddressIndex(0)
# Retrieve wallet components
address = bip44_acc_ctx.PublicKey().ToAddress() # Solana address (base58 encoded)
private_key = bip44_acc_ctx.PrivateKey().Raw().ToHex()
# Use RawCompressed() for the public key (no generic Raw() anymore)
public_key = bip44_acc_ctx.PublicKey().RawCompressed().ToHex()
return {
"mnemonic": mnemonic,
"seed": seed_bytes.hex(),
"address": address,
"public_key": public_key,
"private_key": private_key,
# You can manually store your derivation path string if needed.
"derivation_path": "m/44'/501'/0'/0'/0" # for example
}
if __name__ == "__main__":
# Replace this with your own 64-character hex entropy
hex_entropy = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
try:
wallet = generate_solana_wallet(hex_entropy)
print("Generated Solana Wallet Information:")
print("-------------------------------------")
print("Mnemonic :", wallet["mnemonic"])
print("Seed :", wallet["seed"])
print("Address :", wallet["address"])
print("Public Key :", wallet["public_key"])
print("Private Key :", wallet["private_key"])
print("Derivation Path:", wallet["derivation_path"])
except Exception as e:
print("Error:", str(e))
Cardano
#!/usr/bin/env python3
import sys
import json
from bip_utils import Bip39MnemonicGenerator
from pycardano import HDWallet, Network, Address
from pycardano.key import (
PaymentSigningKey, PaymentVerificationKey,
StakeSigningKey, StakeVerificationKey
)
def generate_cardano_wallet(hex_entropy: str):
# Validate that the provided entropy is exactly 64 hex characters (256 bits)
if len(hex_entropy) != 64:
raise ValueError("Entropy must be a 64-character hex string (256 bits).")
entropy_bytes = bytes.fromhex(hex_entropy)
# 1. Generate a BIP‑39 mnemonic from the entropy.
mnemonic = str(Bip39MnemonicGenerator().FromEntropy(entropy_bytes))
# 2. Create an HD wallet from the mnemonic.
hdwallet = HDWallet.from_mnemonic(mnemonic)
# 3. Derive the spending key at m/1852'/1815'/0'/0/0
hdwallet_spend = hdwallet.derive_from_path("m/1852'/1815'/0'/0/0")
# Extract the 32-byte private key from the extended private key (xprivate_key)
payment_private_key_bytes = hdwallet_spend.xprivate_key[:32]
payment_public_key_bytes = hdwallet_spend.public_key # already correct length
# 4. Derive the staking key at m/1852'/1815'/0'/2/0
hdwallet_stake = hdwallet.derive_from_path("m/1852'/1815'/0'/2/0")
stake_private_key_bytes = hdwallet_stake.xprivate_key[:32]
stake_public_key_bytes = hdwallet_stake.public_key
# 5. Construct the key objects using pycardano key classes.
payment_skey = PaymentSigningKey(payment_private_key_bytes)
payment_vkey = PaymentVerificationKey(payment_public_key_bytes)
stake_skey = StakeSigningKey(stake_private_key_bytes)
stake_vkey = StakeVerificationKey(stake_public_key_bytes)
# 6. Build the payment address from the verification key hashes.
payment_address = Address(
payment_part=payment_vkey.hash(),
staking_part=stake_vkey.hash(),
network=Network.MAINNET # Change to Network.TESTNET if desired
)
# 7. Parse key JSON to extract just the hex string.
payment_skey_hex = json.loads(payment_skey.to_json())["cborHex"]
payment_vkey_hex = json.loads(payment_vkey.to_json())["cborHex"]
stake_skey_hex = json.loads(stake_skey.to_json())["cborHex"]
stake_vkey_hex = json.loads(stake_vkey.to_json())["cborHex"]
return {
"Mnemonic": mnemonic,
"Payment Signing Key": payment_skey_hex,
"Payment Verification Key": payment_vkey_hex,
"Stake Signing Key": stake_skey_hex,
"Stake Verification Key": stake_vkey_hex,
"Payment Address": str(payment_address)
}
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: {} <64-character-hex-entropy>".format(sys.argv[0]))
sys.exit(1)
hex_entropy = sys.argv[1]
try:
wallet_info = generate_cardano_wallet(hex_entropy)
print("\nGenerated Cardano Wallet:")
print("-------------------------")
for key, value in wallet_info.items():
print(f"{key}: {value}")
except Exception as e:
print("Error:", e)
We need your consent to load the translations
We use a third-party service to translate the website content that may collect data about your activity. Please review the details in the privacy policy and accept the service to view the translations.