Quick Usage
No EC-Multiply:
#!/usr/bin/env python3
from typing import List
import json
from bip38 import BIP38
from bip38.cryptocurrencies import Bitcoin as Cryptocurrency
from bip38.wif import private_key_to_wif
# Private key
PRIVATE_KEY: str = "cbf4b9f70470856bb4f40f80b87edb90865997ffee6df315ab166d713af433a5"
# Passphrase / password
PASSPHRASE: str = "bip38" # u"\u03D2\u0301\u0000\U00010400\U0001F4A9"
# Network type
NETWORK:str = "mainnet"
# To show detail
DETAIL: bool = True
# Initialize BIP38 instance
bip38: BIP38 = BIP38(
cryptocurrency=Cryptocurrency, network=NETWORK
)
# Wallet Import Format's
WIFs: List[str] = [
private_key_to_wif(
private_key=PRIVATE_KEY, cryptocurrency=Cryptocurrency, network=NETWORK, wif_type="wif"
), # No compression
private_key_to_wif(
private_key=PRIVATE_KEY, cryptocurrency=Cryptocurrency, network=NETWORK, wif_type="wif-compressed"
) # Compression
]
for WIF in WIFs:
print("WIF:", WIF)
encrypted_wif: str = bip38.encrypt(
wif=WIF, passphrase=PASSPHRASE
)
print("BIP38 Encrypted WIF:", encrypted_wif)
print("BIP38 Decrypted:", json.dumps(bip38.decrypt(
encrypted_wif=encrypted_wif, passphrase=PASSPHRASE, detail=DETAIL
), indent=4))
print("-" * 125)
EC-Multiply:
#!/usr/bin/env python3
from typing import List
import json
import os
from bip38 import BIP38
from bip38.cryptocurrencies import Bitcoin as Cryptocurrency
# Passphrase / password
PASSPHRASE: str = "bip38" # u"\u03D2\u0301\u0000\U00010400\U0001F4A9"
# Network type
NETWORK: str = "mainnet"
# To show detail
DETAIL: bool = True
# Initialize BIP38 instance
bip38: BIP38 = BIP38(
cryptocurrency=Cryptocurrency, network=NETWORK
)
# List of owner salt, seed, public key type, lot, and sequence kwargs
KWARGS: List[dict] = [
# Random owner salt & seed, No compression, No lot & sequence
{"owner_salt": os.urandom(8), "seed": os.urandom(24), "wif_type": "wif", "lot": None, "sequence": None},
# Random owner salt & seed, No compression, With lot & sequence
{"owner_salt": os.urandom(8), "seed": os.urandom(24), "wif_type": "wif", "lot": 863741, "sequence": 1},
# Random owner salt & seed, Compression, No lot & sequence
{"owner_salt": os.urandom(8), "seed": os.urandom(24), "wif_type": "wif-compressed", "lot": None, "sequence": None},
# Random owner salt & seed, Compression, With lot & sequence
{"owner_salt": os.urandom(8), "seed": os.urandom(24), "wif_type": "wif-compressed", "lot": 863741, "sequence": 1},
# With owner salt & seed, No compression, No lot & sequence
{"owner_salt": "75ed1cdeb254cb38", "seed": "99241d58245c883896f80843d2846672d7312e6195ca1a6c", "wif_type": "wif", "lot": None, "sequence": None},
# With owner salt & seed, No compression, With lot & sequence
{"owner_salt": "75ed1cdeb254cb38", "seed": "99241d58245c883896f80843d2846672d7312e6195ca1a6c", "wif_type": "wif", "lot": 567885, "sequence": 1},
# With owner salt & seed, Compression, No lot & sequence
{"owner_salt": "75ed1cdeb254cb38", "seed": "99241d58245c883896f80843d2846672d7312e6195ca1a6c", "wif_type": "wif-compressed", "lot": None, "sequence": None},
# With owner salt & seed, Compression, With lot & sequence
{"owner_salt": "75ed1cdeb254cb38", "seed": "99241d58245c883896f80843d2846672d7312e6195ca1a6c", "wif_type": "wif-compressed", "lot": 369861, "sequence": 1},
]
for kwarg in KWARGS:
intermediate_passphrase: str = bip38.intermediate_code(
passphrase=PASSPHRASE, owner_salt=kwarg["owner_salt"], lot=kwarg["lot"], sequence=kwarg["sequence"]
)
print("Intermediate Passphrase:", intermediate_passphrase)
encrypted_wif: dict = bip38.create_new_encrypted_wif(
intermediate_passphrase=intermediate_passphrase, wif_type=kwarg["wif_type"], seed=kwarg["seed"],
)
print("Encrypted WIF:", json.dumps(encrypted_wif, indent=4))
print("Confirm Code:", json.dumps(bip38.confirm_code(
passphrase=PASSPHRASE, confirmation_code=encrypted_wif["confirmation_code"], detail=DETAIL
), indent=4))
print("BIP38 Decrypted:", json.dumps(bip38.decrypt(
encrypted_wif=encrypted_wif["encrypted_wif"], passphrase=PASSPHRASE, detail=DETAIL
), indent=4))
print("-" * 125)
Last updated